xunit.net

Unit testing code targeting several frameworks at once with .NET Core and xUnit

南楼画角 提交于 2019-12-05 22:02:13
问题 I have some libraries on .NET Core which target net45 and netstandard1.6 and I want to unit-test them. I did dotnet new -t xunittest and that created a new test project targeting netcoreapp1.0 so that it will tests only the .NET Core code. I tried to also compile it to target also net45 but then I got a series of errors on test discovering. My questions is Is there a way to test the code targeting both (maybe more later) frameworks with a single test project or should I make a test project

Getting started with automated integration/unit testing in an existing code base

て烟熏妆下的殇ゞ 提交于 2019-12-05 19:05:12
Background: We have been handed over a very large codebase (1.4 million lines) that is primarily in C#. The application consists primarily of asp.net 2.0 style asmx web services accessing data in a SQL server 2008 database and also in various XML files. There are no existing automated tests in place. We have an automated nightly build in place (CC.NET). We want to introduce some level of automated testing, but refactoring in granular level unit tests for this amount of code seems unlikely. Our first thought is to find a way to construct automated tests that simply call each web service with a

Testing UWP app with xUnit on VS2015

与世无争的帅哥 提交于 2019-12-05 18:33:01
I have managed to create an xUnit project on VS2015 to unit-test UWP apps. There is a background to this question here on stackoverflow which gives some context to this question. I can compile and run the test, however when I reference a project to be tested, the following error comes up. ------ Run test started ------ Updating the layout... Checking whether required frameworks are installed... Registering the application to run from layout... Deployment complete (1857ms). Full package name: "8f4533e5-fec8-415b-94ab-6bce6b37374f_1.0.0.0_x86__5gyrq6psz227t" A user callback threw an exception.

How to add support for xunit's Theory attribute in Approvaltests

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 07:56:35
When I try to use approvals with my unit test decorated with [Theory] attribute it says: System.Exception: System.Exception : Approvals is not set up to use your test framework. It currently supports [NUnit, MsTest, MbUnit, xUnit.net] To add one use ApprovalTests.StackTraceParsers.StackTraceParser.AddParser() method to add implementation of ApprovalTests.StackTraceParsers.IStackTraceParser with support for your testing framework. To learn how to implement one see http://blog.approvaltests.com/2012/01/creating-namers.html at ApprovalTests.StackTraceParsers.StackTraceParser.Parse(StackTrace

App.config for Xunit

a 夏天 提交于 2019-12-05 06:13:26
I'm writing some xUnit tests for some helper classes that relies on some configuration settings, usually stored in App.config or Web.config of the executing project. The config looks like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="FileNamePattern" value="\\d{8}_\\w{4:20}\.png"/> <!-- and the likes --> </appSettings> </configuration> I'm running xUnit 1.9 with the GUI runner (xunit.gui.clr4.exe) and xUnit console runner (on the Jenkins CI server). Currently, I can "inject" these configuration values into the test environments by setting the xunit.gui

xunit add info to output

故事扮演 提交于 2019-12-05 04:35:40
Does anyone know how to add additional info to the output console when running xUnit tests? I'm using testdriven.net, but I don't think that is where my answer lies. I am using a IUseFixture (actually IClassFixture from 2.0) to maintain data between tests. When a test fails I want to output some of that contextual data along with the failure and the stack trace that you usually get. Does anyone know of a hook I can use? n-develop You can use ITestOutputHelper to write any output to the test result view. Just let xUnit inject it into your constructor. using Xunit; using Xunit.Abstractions;

xUnit and Moq do not support async - await keywords

女生的网名这么多〃 提交于 2019-12-05 00:06:00
I am trying to discover how to apply the async and await keywords to my xUnit tests. I am using xUnit 1.9 and Async CTP 1.3. Here is my test case I have an interface which specifies one asynchronous method call public interface IDoStuffAsync { Task AnAsyncMethod(string value); } I have a class which consumes the interface and calls the async method public class UseAnAsyncThing { private readonly IDoStuffAsync _doStuffAsync; public UseAnAsyncThing(IDoStuffAsync doStuffAsync) { _doStuffAsync = doStuffAsync; } public async Task DoThatAsyncOperation(string theValue) { await _doStuffAsync

How can I run xUnit Unit Tests with VS2015 Preview?

情到浓时终转凉″ 提交于 2019-12-04 22:30:37
I added the "xUnit.net runner for Visual Studio" v0.99.8 via Extensions Manager, but when I open the Test Explorer window, it does not seem to pick up any of my unit tests. Also, the Resharper 9 EAP does which is the only version of Resharper that supports VS2015 does seem yet to have the plugin for xUnit Test Runner. How then, can I run xUnit Unit Tests in VS2015 Preview? You can find the answer here: http://blogs.msdn.com/b/webdev/archive/2014/11/12/announcing-asp-net-features-in-visual-studio-2015-preview-and-vs2013-update-4.aspx Visual Studio supports running and debugging for ASP.NET 5

Unit test WebApi2 passing header values

醉酒当歌 提交于 2019-12-04 17:01:50
I am working on a project using WebApi2. With my test project I am using Moq and XUnit. So far testing an api has been pretty straight forward to do a GET like [Fact()] public void GetCustomer() { var id = 2; _customerMock.Setup(c => c.FindSingle(id)) .Returns(FakeCustomers() .Single(cust => cust.Id == id)); var result = new CustomersController(_customerMock.Object).Get(id); var negotiatedResult = result as OkContentActionResult<Customer>; Assert.NotNull(negotiatedResult); Assert.IsType<OkNegotiatedContentResult<Customer>>(negotiatedResult); Assert.Equal(negotiatedResult.Content.Id,id); } Now

dotCover and xUnit not gathering coverage statistics in some environments

扶醉桌前 提交于 2019-12-04 16:43:45
We're using dotCover 2.7 and xUnit.net 1.9.2. On my machine (Windows 7) and a co-worker's machine (Windows 8) we can run dotCover from the command line against one of our unit test assemblies that uses xUnit.net and get correct coverage reporting. On our build machine (Windows Server 2008 R2 Standard) when we run the same thing the only code coverage that dotCover reports is the unit test assembly itself. We're running xUnit.net using the MSBuild task. Here's the relevant pieces from the .msbuild file. <UsingTask TaskName="Xunit.Runner.MSBuild.xunit" AssemblyFile="$(PackagesDir)xunit.$