xunit.net

Visual Studio 2015 Test Explorer does not see XUnit dnx traits

人盡茶涼 提交于 2019-12-01 16:09:23
The Visual Studio 2015 Test Explorer does not recognize my test traits. When I add this to a test in a DNX project: [Trait("Category", "Test")] the test still shows up in the Test Explorer under the No Traits group (when grouping tests by Traits). Looks like this is already logged as an issue: VS 2015 Bugs - Traits and Project Grouping in Test Explorer #485 来源: https://stackoverflow.com/questions/32258618/visual-studio-2015-test-explorer-does-not-see-xunit-dnx-traits

Using xUnit test with UWP app on VS2015

人盡茶涼 提交于 2019-12-01 10:41:51
问题 This is a follow-up to this question. I followed the steps as described here and the sample tests work as expected. This is the first time I got to this working sample, but wait for the real working setup which is where I am having trouble. As a next step to testing my app, I added my UWP app project using "Add Reference..." to the xUnit Test project. Now, after I referencing my project, when I run the test (Run All in Test Explorer pane VS2015) I get the following error: Error Payload

Running xUnit tests on Teamcity using async methods

こ雲淡風輕ζ 提交于 2019-12-01 06:32:01
问题 I made the following xUnit test which is using a HttpClient to call a status api method on a webserver. [Fact] public void AmIAliveTest() { var server = TestServer.Create<Startup>(); var httpClient = server.HttpClient; var response = httpClient.GetAsync("/api/status").Result; response.StatusCode.Should().Be(HttpStatusCode.OK); var resultString = response.Content.ReadAsAsync<string>().Result; resultString.Should().Be("I am alive!"); } This test is running fine locally. But when I commit the

Xunit create new instance of Test class for every new Test ( using WebDriver and C#)

老子叫甜甜 提交于 2019-12-01 04:50:26
Is there any way to run multiple tests in same browser using Webdriver (Selenium) using Xunit, , at present xunit launches new browser for every new test , below is the sample code public class Class1 { private FirefoxDriver driver; public Class1() { driver = new FirefoxDriver(); } [Fact] public void Test() { driver.Navigate().GoToUrl("http://google.com"); driver.FindElementById("gbqfq").SendKeys("Testing"); } [Fact] public void Test2() { driver.Navigate().GoToUrl("http://google.com"); driver.FindElementById("gbqfq").SendKeys("Testing again"); } } While I don't know Selenium, I do know that

Is there an easy way in xunit.net to compare two collections without regarding the items' order?

烈酒焚心 提交于 2019-12-01 02:27:38
In one of my tests, I want to ensure that a collection has certain items. Therefore, I want to compare this collection with the items of an expected collection not regarding the order of the items . Currently, my test code looks somewhat like this: [Fact] public void SomeTest() { // Do something in Arrange and Act phase to obtain a collection List<int> actual = ... // Now the important stuff in the Assert phase var expected = new List<int> { 42, 87, 30 }; Assert.Equal(expected.Count, actual.Count); foreach (var item in actual) Assert.True(expected.Contains(item)); } Is there any easier way to

AutoFixture CompositeDataAttribute does not work with PropertyDataAttribute

此生再无相见时 提交于 2019-12-01 01:43:25
问题 I'm trying to create AutoPropertyDataAttribute based on CompositeDataAttribute from this example AutoFixture: PropertyData and heterogeneous parameters. It works with single set of parameters, but fails with more sets of parameters. Here is code: public static IEnumerable<object[]> NumericSequence { get { yield return new object[] {1}; //yield return new object[] {2}; } } [Theory] [AutoPropertyData("NumericSequence")] public void Test(int? p1, int? p2, int? p3) { Assert.NotNull(p1); Assert

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

折月煮酒 提交于 2019-11-30 21:26:00
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 TestThatGuardsAreTriggeredWhenConnectionStringArgumentIsInvalid( IDeal deal, IDbConnection conn, IDb db, ISender sender, string

xunit Assert.ThrowsAsync() does not work properly?

寵の児 提交于 2019-11-30 16:50:10
So I have a test like the following: [Fact] public void Test1() { Assert.ThrowsAsync<ArgumentNullException>(() => MethodThatThrows()); } private async Task MethodThatThrows() { await Task.Delay(100); throw new NotImplementedException(); } To my surprise, Test1 passes successfully. To make it fail I have to write like this: Assert.Throws<ArgumentNullException>(() => MethodThatThrows().Wait()); What is the purpose of ThrowsAsync(), if it does not work in the scenario above? You're supposed to await the result (see xunit's acceptance tests ). [Fact] public async Task Test1() { await Assert

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

人盡茶涼 提交于 2019-11-30 13:42:59
问题 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? 回答1: If you reference Microsoft.NET.Test.Sdk >= 15.3.0 in your project it automatically turns on the required MSBuild properties,

Should GetEnvironmentVariable Work in xUnit Test?

随声附和 提交于 2019-11-30 12:58:14
问题 If I set environment variables for a .Net Core web project in Visual Studio 2017 using the project properties page, I can read the value of the variable using Environment.GetEnvironmentVariable ; however, when I set the environment variable for my xUnit testing project and then debug the test, Environment.GetEnvironmentVariable always returns null. Is there something about the fact that it is a testing project that should prevent the variable from being used the same as with the web project?