xunit.net

Is Assert.Fail() considered bad practice?

I use Assert.Fail a lot when doing TDD. I'm usually working on one test at a time but when I get ideas for things I want to implement later I quickly write an empty test where the name of the test method indicates what I want to implement as sort of a todo-list. To make sure I don't forget I put an Assert.Fail() in the body. When trying...

Help troubleshooting System.BadImageFormatException:

While debugging through a .NET 3.5 SP1 project which is contacting a local web service, I'm receiving the exception System.BadImageFormatException: "Bad Class Token" Of course there aren't much more details about what's causing the exception. I can tell that the method where this occurs, which is in the same class as it's caller, the ...

NUnit vs. MbUnit vs. MSTest vs. xUnit.net

There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: http://www.codeplex.com/xunit/Wiki/View.aspx?title=Comparisons 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? ...

Is there a test runner for .NET tests that can run multi-threaded to take advantage of multi-core machines?

I'm setting up CI at present using Thoughtworks Studios' Cruise, Gallio to run xunit.net fact/tests, and ncover 2 to do code-coverage. I noticed that running the code-coverage pegs one of the four CPUs that our build-agent server has, and wondered whether there was a multi-threaded test-runner that I might use instead, to take advantage...

Unit Testing with functions that return random results

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 approa...

Running XUnit.net Tests with TestDriven.net

I've used NUnit for years and I wanted to try XUnit. So I installed XUnit and ran the executable that allowed you to run XUnit via TD.net. I can't seem to run more than one test at a time. With NUnit + TD.net, I could click on the filename in the solution and run all the tests in the file. I can't seem to do that with XUnit + TD.net...

xUnit : Assert two List<T> are equal ?

Hi I'm new to TDD and xUnit so I want to test my method that is something like : List<T> DeleteElements<T>(this List<T> a, List<T> b); of course that's not the real method :) 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> expecte...

How do I automate unit tests for a console application in TeamCity?

I've written a console application that has a number of unit tests and I'm wanting to include it in my nant build script so that it will be run on our TeamCity CIS. Unfortunately I'm not quite sure how to do that. The nant script has examples of current projects that have been added...they they all have to supply the assemblies that nee...

Extend xUnit.NET to use custom code when processing a class and locating test methods

I'm a big fan of the xUnit.NET framework; I find it light, simple, clean, and extensible. Now let's say that I have a class like so: public class AdditionSpecification { static int result; public void Because() { result = 2 + 2; } public void Result_is_non_zero() { Assert.True(result <> 0); } public void Resu...

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

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. ...

Watin Tests fail on CC.Net

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 expecte...

TestDriven.NET and native C Library

I am working on a C# application that makes calls to a native Windows C dll. We use TestDriven.NET with xUnit for testing. The problem is, whenever we run unit tests that use the C library (which we did not write), and then try to build afterwards, there is a build error about how the library is being used by another process. To fix i...

BDD, Specifications, and "Specification Reports" with xUnit.NET?

I am a new, but huge fan, of the BDD approach to software development and "specification". I have been making use of xUnit.NET, Moq, and an extension to xUnit.NET that allows me to perform BDD-style testing (I'm using testing loosely, as its not really so much testing as it is specifying expected behavior). Currently, I run all my tests ...

Can TransactionScope rollback be used with Selenium or Watin?

I am trying to do some automated web testing of my ASP.NET application. I was hoping to use the AutoRollback attribute from Xunit.net extensions to undo any database changes that were made during the test. AutoRollback uses TransactionScope to start a transaction before the test and roll it back afterwards. When I try to hit my web ...

Non-code-generated forwarding shim for testing private methods

In general, I design classes in such a manner as to not require access to privates for testing purposes. An InternalsVisibleTo can also assist. However, I'm currently dealing with a codebase that has a few area which have become reliant on the private accessors mechanism in VSTS (i.e., using VSCodeGenAccessors to generate *_Accessor cl...

How can I generate ASP.NET MVC URLs inside a unit test project?

How can I generate the URLs corresponding to the controller, action, and parameters (for a given ASP.NET MVC project) in another project (a class library used for testing)? All I have found so far is HtmlHelper.GenerateRouteLink, but didn't find yet how to pass the correct request context and route collection. ...

Trapping Error Status in MSBuild

As part of some build automation of running xUnit.net tests with MSBuild, I'm running into a case where I need to loop over a batch of items. Inside the loop, I need to detect whether an iteration failed, but I want to continue executing regardless. Then after the batched bit, I need to know whether one or more errors have occurred in ...

MSBuild task for combining NUnit or MSTest XML results

I have a set of NUnit XML result files (produced by xUnit.NET via the NUnitXml parameter to the Xunit.Runner.MSBuild.xunit msbuild task pretty much as in http://stackoverflow.com/questions/517560/how-do-i-get-team-build-to-show-test-results-and-coverage-for-xunit-net-test-suit and http://jonnekats.wordpress.com/2009/05/07/integrate-xunit...

Is there a way to unit test an async method?

I am using Xunit and NMock on .NET platform. I am testing a presentation model where a method is asynchronous. The method creates an async task and executes it so the method returns immediately and the state I need to check aren't ready yet. I can set a flag upon finish without modifying the SUT but that would mean I would have to keep ...

Localized xUnit.net Output in Visual Studio Output Window

Hi folks I am using xUnit.net (1.5, but 1.1 seems to have the same issue) in a Visual Studio 2008 solution (with a simple post build event). The host system (Windows XP) is the localized german version and vs2008 is the english version. The VS output window shows the localized german output like this: 1) IXmlSerializableTest.XmlSerial...