Questions tagged [xunit]

xUnit is the collection name for unit-testing compliant frameworks following a specific architecture. Implementation differs from language to language but the framework should consist of a Test Runner, Test Case, Test Fixture (Context), Test Suite, Test Execution, Test Result Formatter and Assertions

xUnit has been implemented for most languages, examples include JUnit, NUnit, CUnit, CppUnit, xUnit.net and more. The first implementation was made for Smalltalk by Kent Beck and is called SUnit.

3147 questions
250
votes
5 answers

Assert an Exception using XUnit

I am a newbie to XUnit and Moq. I have a method which takes string as an argument.How to handle an exception using XUnit. [Fact] public void ProfileRepository_GetSettingsForUserIDWithInvalidArguments_ThrowsArgumentException() { //arrange …
wandermonk
  • 6,856
  • 6
  • 43
  • 93
211
votes
8 answers

What is the JUnit XML format specification that Hudson supports?

I have Hudson as continuous integration server and I want to use option 'Publish JUnit test result report'. But I don't use xUnit tools for testing, instead of that i have shell scripts which run tests and return results in simple format. I am…
Vlad Krylov
  • 2,684
  • 3
  • 21
  • 23
183
votes
10 answers

NUnit vs. xUnit

What are the differences between NUnit and xUnit.net? What's the point of developing two of them, not only one? I've read that xUnit is being developed by inventor of NUnit: xUnit.net is a unit testing tool for the .NET Framework. Written by the…
Ruslan
  • 2,678
  • 3
  • 22
  • 25
171
votes
46 answers

Visual Studio 2015 or 2017 does not discover unit tests

EDIT 2016-10-19: The original question was about an issue specific to VS2015 CTP6 with the XUnit test runner. It's clear from the answers that there is a much broader issue with unit test discovery in Visual Studio which may occur in many different…
167
votes
8 answers

What's the idiomatic way to verify collection size in xUnit?

I have in my test suite a test that goes something like this: [Fact] public void VerifySomeStuff() { var stuffCollection = GetSomeStuff(); Assert.Equal(1, stuffCollection.Count()); } This test works as I expect, but when I run it xUnit…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
162
votes
6 answers

xUnit : Assert two List are equal?

I'm new to TDD and xUnit so I want to test my method that looks something like: List DeleteElements(this List a, List b); Is there any Assert method that I can use ? I think something like this would be nice List values = new…
Petar Petrov
  • 2,729
  • 2
  • 22
  • 17
159
votes
6 answers

Python unittests in Jenkins?

How do you get Jenkins to execute python unittest cases? Is it possible to JUnit style XML output from the builtin unittest package?
erikbstack
  • 12,878
  • 21
  • 81
  • 115
152
votes
12 answers

Pass complex parameters to [Theory]

Xunit has a nice feature: you can create one test with a Theory attribute and put data in InlineData attributes, and xUnit will generate many tests, and test them all. I want to have something like this, but the parameters to my method are not…
zchpit
  • 3,071
  • 4
  • 28
  • 43
143
votes
7 answers

How do I skip specific tests in xUnit based on current platform

I have an assembly that I've built on Windows I want to run the xUnit tests on mono in Linux. However, I have found that while 400 of these tests can run (in order), that certain tests either hang the xUnit runner, or bring it down entirely. I…
metdos
  • 13,411
  • 17
  • 77
  • 120
102
votes
7 answers

Populate IConfiguration for unit tests

.NET Core configuration allows so many options to add values (environment variables, json files, command line args). I just can't figure out and find an answer how to populate it via code. I am writing unit tests for extension methods to…
monty
  • 7,888
  • 16
  • 63
  • 100
90
votes
5 answers

Is it idiomatic Ruby to add an assert( ) method to Ruby's Kernel class?

I'm expanding my Ruby understanding by coding an equivalent of Kent Beck's xUnit in Ruby. Python (which Kent writes in) has an assert() method in the language which is used extensively. Ruby does not. I think it should be easy to add this but is…
Andrew Harmel-Law
  • 7,739
  • 12
  • 44
  • 55
87
votes
5 answers

Is there a set of "Lorem ipsums" files for testing character encoding issues?

For layouting we have our famous "Lorem ipsum" text to test how it looks like. What I am looking for is a set of files containing Text encoded with several different encodings that I can use in my JUnit tests to test some methods that are dealing…
Fabian Barney
  • 14,219
  • 5
  • 40
  • 60
84
votes
3 answers

What happened to Assert.DoesNotThrowAsync() in xUnit?

I migrated my unit test project from version 2.0.0-beta-{something} to 2.0.0 (stable) through NuGet. It seems like Assert.DoesNotThrowAsync() is not available anymore. For Example: [Fact] public void CanDeleteAllTempFiles() { …
der_michael
  • 3,151
  • 1
  • 24
  • 43
77
votes
8 answers

Unit test exception messages with xUnit

I'm currently converting my MsTest unit tests to xUnit. With xUnit, is there a way to test exception messages? Is it correct to test exception messages as opposed just the exception type?
sduplooy
  • 14,340
  • 9
  • 41
  • 60
72
votes
8 answers

Is it possible to use Dependency Injection with xUnit?

I have a test class with a constructor that needs an IService. public class ConsumerTests { private readonly IService _service; public ConsumerTests(IService servie) { _service = service; } [Fact] public void…
Rookian
  • 19,841
  • 28
  • 110
  • 180
1
2 3
99 100