xunit.net

Unit testing a .NET Standard 1.6 library

Deadly 提交于 2019-11-30 11:17:53
I am having trouble finding up to date documentation on how to unit test a .NET Standard 1.6 class library (which can be referenced from a .NET Core project). Here is what my project.json looks like for my library: { "supports": {}, "dependencies": { "Microsoft.NETCore.Portable.Compatibility": "1.0.1", "NETStandard.Library": "1.6.0", "Portable.BouncyCastle": "1.8.1.2" }, "frameworks": { "netstandard1.6": {} } } Now the left over task is to be able to create some sort of a project that can do the unit testing. The goal is to use xUnit since it seems that this is what the .NET Core team is

How can I add an assembly binding redirect to a .net core unit test project?

余生颓废 提交于 2019-11-30 08:11:33
I'm trying to create a .net core unit test project against framework 4.6.1 which tests an project dependent on Microsoft.SqlServer.Types (10.0.0.0). Prior to .net core I'd add an app.config file with the binding redirect. I've tried this but the binding redirect does not seem to be picked up when I run from visual studio. What can I do to fix the binding redirect? If you reference Microsoft.NET.Test.Sdk >= 15.3.0 in your project it automatically turns on the required MSBuild properties, as Fabian says below. See here . You can add the following settings to your .csproj file: <PropertyGroup>

xUnit.net does not capture console output

元气小坏坏 提交于 2019-11-30 06:51:12
问题 I just started testing xUnit.net, but it doesn't seem to capture any output (Console, Debug, Trace), as I would have expected. Is that possible? I am using a sample .NET 4.0 class-library with xUnit.net 1.8. 回答1: In general, it's a bad road to go down to be reliant on logging and tests. The pass/fail should be the outcome of the tests. And they simply shouldn't get to the stage where there's enough stuff going on that looking at a trace will be necessary. The xunit.gui.exe shows Console and

How to combine PropertyData and AutoNSubstituteData attributes in xunit/autofixture?

淺唱寂寞╮ 提交于 2019-11-30 05:48:39
问题 I am using the [AutoNSubstituteData] attribute, which was posted here: AutoFixture, xUnit.net, and Auto Mocking I would like to combine this with the [PropertyData("")] attribute from xunit extensions. This is my test: public static IEnumerable<string[]> InvalidInvariant { get { yield return new string[] { null }; yield return new [] { string.Empty }; yield return new [] { " " }; } } [Theory, AutoNSubstituteData, PropertyData("InvalidInvariant")] public void

Unit testing a .NET Standard 1.6 library

混江龙づ霸主 提交于 2019-11-29 16:58:10
问题 I am having trouble finding up to date documentation on how to unit test a .NET Standard 1.6 class library (which can be referenced from a .NET Core project). Here is what my project.json looks like for my library: { "supports": {}, "dependencies": { "Microsoft.NETCore.Portable.Compatibility": "1.0.1", "NETStandard.Library": "1.6.0", "Portable.BouncyCastle": "1.8.1.2" }, "frameworks": { "netstandard1.6": {} } } Now the left over task is to be able to create some sort of a project that can do

AutoFixture: PropertyData and heterogeneous parameters

社会主义新天地 提交于 2019-11-29 14:22:30
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 patientFirstName , HtmlOutputBuilder sut ) { sut.DoSomething(); // More code } The problem is that I'm using

xUnit v1 tests appear in xUnit GUI (xunit.gui.clr4.exe) but not VS 2012 Test Explorer

我的未来我决定 提交于 2019-11-29 07:32:46
I have an F# Class Library with the "xUnit.net" and "xUnit.net Runners" packages installed using NuGet. I have the following code: module XUnitTest open Xunit [<Fact>] let Test () = do Assert.True (1 = 2) () When I run the xUnit GUI (xunit.gui.clr4.exe, which NuGet adds to (projectdirectory)\packages\xunit.runners.1.9.1\tools), and load the assembly built by this project, the Test () method appears, and fails when I run it, as expected. However, I cannot get the test to appear in VS 2012's Test Explorer, no matter how many times I rebuild, restart, etc. If I click Run All, the build output

How do I get Team Build to show test results and coverage for xUnit.net test suite?

坚强是说给别人听的谎言 提交于 2019-11-29 07:12:52
Has anybody had any success getting Team Build to show xUnit.net test results and code coverage in the build report? The MSBuild runner is running the tests just fine and the results are in the log file, but the test results and code coverage results areas of the build report say "No test result" and "No coverage result" respectively. Is Team Build looking for a certain location / format for the test results to be exported by the xUnit.net runner? TFS/TeamBuild definitely requires the test results in a particular format, they also need to be specifically published to TFS as well. I'm currently

How to set the test case sequence in xUnit

两盒软妹~` 提交于 2019-11-28 22:56:51
I have written the xUnit test cases in C#. That test class contains so many methods. I need to run the whole test cases in a sequence. How can I set the test case sequence in xUnit? In xUnit 2.* this can be achieved using the TestCaseOrderer attribute to designate an ordering strategy, which can be used to reference an attribute that is annotated on each test to denote an order. For example: Ordering Strategy [assembly: CollectionBehavior(DisableTestParallelization = true)] public class PriorityOrderer : ITestCaseOrderer { public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable

Unit Testing with functions that return random results

元气小坏坏 提交于 2019-11-28 18:31:06
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 approach. I also realize that unless I am able to control my Random generator, there will not be a