xunit.net

Test parameterization in xUnit.net similar to NUnit

不羁岁月 提交于 2019-11-27 00:32:18
问题 Are there any means in xUnit.net framework similar to the following features of NUnit? [Test, TestCaseSource("CurrencySamples")] public void Format_Currency(decimal value, string expected){} static object[][] CurrencySamples = new object[][] { new object[]{ 0m, "0,00"}, new object[]{ 0.0004m, "0,00"}, new object[]{ 5m, "5,00"}, new object[]{ 5.1m, "5,10"}, new object[]{ 5.12m, "5,12"}, new object[]{ 5.1234m, "5,12"}, new object[]{ 5.1250m, "5,13"}, // round new object[]{ 5.1299m, "5,13"}, //

Execute unit tests serially (rather than in parallel)

 ̄綄美尐妖づ 提交于 2019-11-27 00:19:31
问题 I am attempting to unit test a WCF host management engine that I have written. The engine basically creates ServiceHost instances on the fly based on configuration. This allows us to dynamically reconfigure which services are available without having to bring all of them down and restart them whenever a new service is added or an old one is removed. I have run into a difficulty in unit testing this host management engine, however, due to the way ServiceHost works. If a ServiceHost has already

Pass complex parameters to [Theory]

断了今生、忘了曾经 提交于 2019-11-26 19:44:28
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 'simple data' (like string , int , double ), but a list of my class: public static void WriteReportsToMemoryStream( IEnumerable<MyCustomClass> listReport, MemoryStream ms, StreamWriter writer) { ... } quetzalcoatl There are many xxxxData attributes in XUnit. Check out for example the PropertyData attribute. You can implement a property that returns

Why is the xUnit Runner not finding my tests

守給你的承諾、 提交于 2019-11-26 18:52:45
I have a xUnit.net Test as follows: static class MyTestClass { [Fact] static void MyTestMethod() { } } The xUnit plugin for VS 2012 says: No tests found to run. TestDriven.net runs it fine but mentions something about Ad hoc : 1 passed, 0 failed, 0 skipped (see 'Task List'), took 0.47 seconds (Ad hoc) TeamCity, xunit.gui.exe and xunit.console.exe and Visual Studio also can't find TestMethod (I've got xunit.runner.visualstudio installed and VS is seeing some tests.) What gives? Ruben Bartelink TL;DR your Test Classes must be public (but your Test Methods can be private and/or static ) For

Mocking IPrincipal in ASP.NET Core

送分小仙女□ 提交于 2019-11-26 17:23:27
I have an ASP.NET MVC Core application that I am writing unit tests for. One of the action methods uses User name for some functionality: SettingsViewModel svm = _context.MySettings(User.Identity.Name); which obviously fails in the unit test. I looked around and all suggestions are from .NET 4.5 to mock HttpContext. I am sure there is a better way to do that. I tried to inject IPrincipal, but it threw an error; and I even tried this (out of desperation, I suppose): public IActionResult Index(IPrincipal principal = null) { IPrincipal user = principal ?? User; SettingsViewModel svm = _context

Watin Tests fail on CC.Net

霸气de小男生 提交于 2019-11-26 16:33:04
问题 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

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

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:52:10
问题 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

Why is the xUnit Runner not finding my tests

百般思念 提交于 2019-11-26 06:38:40
问题 I have a xUnit.net Test as follows: static class MyTestClass { [Fact] static void MyTestMethod() { } } The xUnit plugin for VS 2012 says: No tests found to run. TestDriven.net runs it fine but mentions something about Ad hoc: 1 passed, 0 failed, 0 skipped (see \'Task List\'), took 0.47 seconds (Ad hoc) TeamCity, xunit.gui.exe and xunit.console.exe and Visual Studio also can\'t find TestMethod (I\'ve got xunit.runner.visualstudio installed and VS is seeing some tests.) What gives? 回答1: TL;DR

Mocking IPrincipal in ASP.NET Core

痞子三分冷 提交于 2019-11-26 05:24:25
问题 I have an ASP.NET MVC Core application that I am writing unit tests for. One of the action methods uses User name for some functionality: SettingsViewModel svm = _context.MySettings(User.Identity.Name); which obviously fails in the unit test. I looked around and all suggestions are from .NET 4.5 to mock HttpContext. I am sure there is a better way to do that. I tried to inject IPrincipal, but it threw an error; and I even tried this (out of desperation, I suppose): public IActionResult Index

NUnit vs. MbUnit vs. MSTest vs. xUnit.net [closed]

こ雲淡風輕ζ 提交于 2019-11-26 02:15:29
问题 There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: http://xunit.github.io/docs/comparisons.html Now I am to choose the best one for us. But how? Does it matter? Which one is most future proof and has a decent momentum behind it? Should I care about the features? While xUnit seems to be most modern and specifically designed for .NET, NUnit again seems to be the one that is widely accepted. MSTest again is already integrated into Visual