xunit.net

Which is better? Unit-test project per solution or per project?

大憨熊 提交于 2019-11-28 08:58:42
Is it better to have a unit-test project per solution or a unit-test project per project? With per solution, if you have 5 projects in the solution you end-up with 1 unit-test project containing tests for each of the 5 projects. With per project, if you have 5 projects in the solution you end-up with 5 unit-test projects. What is the right way? I think it's not the same question as Write Unit tests into an assembly or in a separate assembly? Assemblies are a packaging/deployment concern, so we usually split them out because we don't want to deploy them with our product. Whether you split them

AutoFixture: PropertyData and heterogeneous parameters

拥有回忆 提交于 2019-11-28 08:00:36
问题 Given the following test: [Theory] [PropertyData("GetValidInputForDb")] public void GivenValidInputShouldOutputCorrectResult( string patientId , string patientFirstName ) { var fixture = new Fixture(); var sut = fixture.Create<HtmlOutputBuilder>(); sut.DoSomething(); // More code } I want to encapsulate fixture creation in its own class, something akin to: [Theory] [CustomPropertyData("GetValidInputForDb")] public void GivenValidInputShouldOutputCorrectResult( string patientId , string

xUnit : Assert two List<T> are equal?

余生长醉 提交于 2019-11-27 19:33:56
I'm new to TDD and xUnit so I want to test my method that looks something like: List<T> DeleteElements<T>(this List<T> a, List<T> b); Is there any Assert method that I can use ? I think something like this would be nice List<int> values = new List<int>() { 1, 2, 3 }; List<int> expected = new List<int>() { 1 }; List<int> actual = values.DeleteElements(new List<int>() { 2, 3 }); Assert.Exact(expected, actual); Is there something like this ? xUnit.Net recognizes collections so you just need to do Assert.Equal(expected, actual); // Order is important You can see other available collection

Run code once before and after ALL tests in xUnit.net

半城伤御伤魂 提交于 2019-11-27 18:39:55
TL;DR - I'm looking for xUnit's equivalent of MSTest's AssemblyInitialize (aka the ONE feature it has that I like). Specifically I'm looking for it because I have some Selenium smoke tests which I would like to be able to run with no other dependencies. I have a Fixture that will launch IisExpress for me and kill it on disposal. But doing this before every test hugely bloats runtime. I would like to trigger this code once at the start of testing, and dispose of it (shutting down the process) at the end. How could I go about doing that? Even if I can get programmatic access to something like

xUnit.net: Global setup + teardown?

巧了我就是萌 提交于 2019-11-27 17:25:53
This question is about the unit testing framework xUnit.net . I need to run some code before any test is executed, and also some code after all tests are done. I thought there should be some kind of attribute or marker interface to indicate the global initialization and termination code, but couldn't find them. Alternatively, if I invoke xUnit programmatically, I can also achieve what I want with the following code: static void Main() { try { MyGlobalSetup(); RunAllTests(); // What goes into this method? } finally { MyGlobalTeardown(); } } Can anyone provide me a hint about how to

Watin Tests fail on CC.Net

半腔热情 提交于 2019-11-27 13:49:46
I'm running Watin tests with xUnit on CC.Net under Windows Server 2003. I have lots of tests that all run fine on development boxes with TestDriven.Net and on the server with the xUnit gui app. However, when CC.Net runs the tests (as part of an MSBuild task) the function ie.ContainsText("some text to find"); never returns the expected value. Other functions and properties on the IE object appear to work fine: Button(...).Click(), TextBox(...).Value, etc. I am aware that the service account needs "Allow service to interact with the desktop". I have tried this running CC service under Local

How can XUnit be configured to show just the method name in the Visual Studio 2015 Test Explorer?

核能气质少年 提交于 2019-11-27 12:02:07
When using xunit.runner.visualstudio version 2.0.1 in Visual Studio 2015, the names of the tests show up fully qualified. Is there a way for the tests to show only the method name? Consider the following test: - namespace MySolution.Tests { public class MyTestClass { [Fact] public void ClassUnderTest_WhenDefaultConstructorUsed_SomePropertyIsNotNull() { *... test code in here* } } } In the Test Explorer this shows as: - MySolution.Tests.MyTestClass.ClassUnderTest_WhenDefaultConstructorUsed_SomePropertyIsNotNull Using MSTest/VSTest this will show up as: - ClassUnderTest

Unit Testing with functions that return random results

北城以北 提交于 2019-11-27 11:37:42
问题 I don't think that this is specific to a language or framework, but I am using xUnit.net and C#. I have a function that returns a random date in a certain range. I pass in a date, and the returning date is always in range of 1 to 40 years before the given date. Now I just wonder if there is a good way to unit test this. The best approach seems to be to create a loop and let the function run i.e. 100 times and assert that every of these 100 results are in the desired range, which is my current

xUnit.net: Global setup + teardown?

若如初见. 提交于 2019-11-27 04:11:58
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 7 years ago . This question is about the unit testing framework xUnit.net. I need to run some code before any test is executed, and also some code after all tests are done. I thought there should be some kind of attribute or marker interface to indicate the global initialization and termination code, but couldn't find them. Alternatively, if I invoke xUnit

Which is better? Unit-test project per solution or per project?

孤者浪人 提交于 2019-11-27 02:32:13
问题 Is it better to have a unit-test project per solution or a unit-test project per project? With per solution, if you have 5 projects in the solution you end-up with 1 unit-test project containing tests for each of the 5 projects. With per project, if you have 5 projects in the solution you end-up with 5 unit-test projects. What is the right way? I think it's not the same question as Write Unit tests into an assembly or in a separate assembly? 回答1: Assemblies are a packaging/deployment concern,