Support Visual Studio Test Runner (Please Read and Respond!)

Coordinator
Aug 20, 2008 at 11:20 PM
We started investigating adding support for running tests with Visual Studio’s built-in test runner. It would require Visual Studio 2008 SP1, and would require Professional edition or higher.

In order to support running xUnit.net tests in Visual Studio, we discovered that the project needs to be marked as one of Visual Studio’s Test projects (essentially, it’s a C#/VB.NET project that has extra bits inside it that tell Visual Studio the project contains tests). Projects which are marked this way cannot be opened in versions of Visual Studio that do not have unit testing support installed (this includes Standard and Express editions, which do not offer unit testing, as well as any user who opts not to install the unit testing support).

Practically speaking, this causes the following to be true:
  • You must have a separate project for tests. You cannot place your tests inside your main project.
  • If you have an existing project with tests in it, you need to edit the .csproj file to add the extra bits into it. (You can also start over with a new project and port the code, but hand editing the .csproj seems easier and more success-prone.)
  • If you create a new Unit Test project, you will need to remember to remove any references to the Visual Studio Test DLLs, since these will not be present unless Visual Studio is installed (for example, on your continuous integration server).
  • If you forget to change the project type, the support simply won’t work. There will not be any feedback as to why; the tests simply won’t show up in Visual Studios Test views.
  • If your project is consumed by many users with various versions of Visual Studio (for example, if you’re running an open source project), you are more likely to run into the version limitations than if you’re using xUnit.net for an internal project with a consistent developer platform.
Given this context, there are two questions:
Aug 20, 2008 at 11:38 PM
My votes are included in your  list, but for reference, I am far more interested in an integrated runner than a stand-alone GUI runner. If I'm not running in the IDE, it's an MSBuild :)
Aug 21, 2008 at 12:12 AM
I find the extra stuff the VS test runner requires makes it not worth the effort.  I would much rather see development cycles going into support for Resharper categories and Team City integration.
Aug 21, 2008 at 5:32 AM
I prefer using the TestDriven.NET runner in VS over the VS runner, seems slower. However, if you have the option of doing this, running it in TestDrive.NET, or running it using Resharper, the better options we have.
Aug 21, 2008 at 2:56 PM
I'd also rather see the cycles go into R# support.  I really dislike the VS test environment for a lot of reasons, not least of which I if I'm cursoring through projects in the solution explorer and I happen to hit a VS test project I have to watch my entire IDE freeze for three seconds while it loads that stupid test bar.  Also, as you mentioned, this breaks if you go to an environment that doesn't have VS testing support. 

I usually run my unit tests either through TD.NET or just using NAnt.
Aug 22, 2008 at 2:58 AM
I'm biased, but I vote yes for VS.NET integration. It'll help more teams at MS potentially adopt xUnit.NET and the VS test runner will get better. :)
Aug 25, 2008 at 7:10 PM
This is an important feature, but I can't see myself using it until VS improves it's test startup times.  Everytime I run my mstest tests, VS decides to re-verify that all of the projects in my solution have been built.  For me, the main reason that xUnit.NET is attractive is that it's not integrated with VS (aka fast) and the IP is owned by Microsoft (no LCA hassles).  Perhaps these perf issues have been fixed in VS9 SP1?  If not, I rank this just below the GUI runner.
Aug 26, 2008 at 4:14 PM
A standalone GUI Runner would be the top priority for me, but I could happily live with it integrated into VS.Net.
Aug 26, 2008 at 5:46 PM
For my team, we've got R# so we're good.  But the *other* teams in the company don't.  They're going to use MSTest because its built-in.  Would the "stand-alone" runner be integrable with the Visual Studio IDE?  (just a tool window!); if so I think that solves my evangelism problem.  "Just install xUnit and use its dockable tool window instead of the MSTest Test View windows" might work.  Convincing them to leave the IDE to go launch some other program won't go over very well.
Aug 27, 2008 at 12:57 PM
I agree with flank42.  Rolling xunit's own an integrated tool window/menu system would be sufficient and probably simpler in the sense that you would not be coupled to MS's awkward (and substandard) testing framework/environment. 
Aug 27, 2008 at 2:42 PM
For those without R#, I can see VS being a useful addition. Personally, I'd like to see xunit's support of other systems (such as TeamCity, Gallio, etc) be enhanced first. After all, most people that want to use the xunit in VS without R# will already be using TestDriven.NET. Still, I think this would be a good idea in the long run.
Aug 28, 2008 at 12:01 AM
I'm gonna have to +1 the Resharper support opinions..
Aug 29, 2008 at 10:15 PM
I vote for VS integration!
Sep 13, 2008 at 6:04 PM
100% must have feature.

VS test runner is the most convinient one. Actually it's the only reason why many (and my team among them) use MSTest.

You don't need to install and manage any 3d party plugins, thats a big plus. The shourtcuts and speed and ui are really convinient.

Will you support the test output also?

Sep 14, 2008 at 9:14 AM
I would love that ...

Although I'm a big fan of Resharper I think it would be great if Xunit could be used inside VS without any extra tooling.  This would enable developers without a unit testing background to start working with a solid testing tool right from the start (which MSTest is definitely not).

But one Question: Is there a way to enable Xunit to run with the VS Test runner without using VSMDI-files? We are constantly experiencing problems with our TFS-sourcecontrol and self-duplicating VSMDI-files at our shop. I heard of several others who struggled with the same kind of problem, too . . .
Sep 14, 2008 at 9:39 AM
> which MSTest is definitely not.

Why, btw?

It has all (almost) the features of xUnit / NUnit, same execution model as xUnit (class instance per test), and works nice out of the box.

The only thing that i like in xUnit in comprasion to MSTest is less attributes, Expect.Throws (altho it can be easely implemented as extension method with NUnit / MSTest). So it's just about a bit cleaner code.
Coordinator
Sep 14, 2008 at 3:41 PM
Edited Sep 14, 2008 at 3:49 PM
But one Question: Is there a way to enable Xunit to run with the VS Test runner without using VSMDI-files?

We won't know for sure until it's done, but I suspect the answer is probably "no".
Sep 15, 2008 at 8:36 AM
@agornik
Have you ever tried to write tests with test case class inheritance? A short example:

In some situations it might be useful to implement the testhandlers (TestInitialize, TestCleanup)  and test methods in a baseclass. The concrete testclass only supplies the object to be tested. We did this in a project that was able to swap out the ioc-container. With that we ensured a common behavior between all ioc adapters. Test case class inheritance is basically supported by MSTest, BUT testbase class and derived class must reside in the same assembly. Besides that you pretty fast find out that tests written that way aren't run on the TFS-Build :-(

So when you're using a test case class per class organization scheme it's probably not so important to you. If you're wanting to do things like the one I described above or tend to go into into the direction of a test case class per fixture organization scheme (for instance when you're doing BDD with a Specification base class) it pretty fast becomes a showstopper.

@Brad
Mh, it would have been nice, but I guess I can live with it as long I'm able to run xunit without additional tools . . .



Sep 15, 2008 at 5:34 PM
> Have you ever tried to write tests with test case class inheritance?

All our tests are in test class hierarchy =).

> Test case class inheritance is basically supported by MSTest, BUT testbase class and derived class must reside in the same assembly.

I don't see this restriction in VS 2008. Our testbase class with TestInitialize, TestCleanup is in different assembly.

> Besides that you pretty fast find out that tests written that way aren't run on the TFS-Build :-(

This is obviously a TFS problem. We use CCNet and it works great.
Sep 16, 2008 at 7:25 AM
>All our tests are in test class hierarchy =).

Mh, interesting . . .

>> I don't see this restriction in VS 2008. Our testbase class with TestInitialize, TestCleanup is in different assembly.

Try this one out. Put RootTest and DerivedTest in different assemblies. Those tests are not discovered by the test explorer . . .

    [TestClass]
    public abstract class RootTest
    {
        [TestInitialize]
        public void BeforeEachTest() { }

        [TestCleanup]
        public void AfterEachTest() { }

        [TestMethod]
        public void FirstTest()
        {
            var obj = CreateObject();
            Assert.IsNotNull(obj);
        }

        protected abstract object CreateObject();
    }

    [TestClass]
    public class DerivedTest : RootTest
    {
        protected override object CreateObject() {  return new object();  }
    }

>> This is obviously a TFS problem. We use CCNet and it works great.

True, but frustrating never the less since we use the TFS . . . .
Jun 30, 2009 at 10:39 PM

I have a team that is using Xunit and we are struggling to get the tests to work with an integrated Team Build. We primilary use MSTEST unit tests, is there an easy way to convert xunit tests to MStest tests?

Thanks,

Jul 1, 2009 at 7:43 AM

@ianceicys: Just been down the road, look at my recent posts on StackOverflow - they should give good pointers. Re conversion, I did a pile of of removals of [TestClass], replaces of IsNull, IsEqual, IsNotEqual, Assert.Fail, TestMethod.  Then you need to replace any TestInitalize/Cleanups, but they are less common. One thing you'll probably run into is VSTT private accessors - I ended up generating ones with publicize.exe and checking the bins in as VS2008 Test References get ignored without it (trying to run without VS on the build agent).  Then I ended up having to install VS for now as to get test results into the TFS repoisitory you need to do a mstest/publish, which only works with VSTT and TFC installed on the agent box. (The projects still need to reference Microsoft.VisualStudio.QualityTools.UnitTests if you use a publicize.exe _Accessor assembly, but this gets onto an agent box with TeamBuild anyway IIRC)

 

Before you start this work, ask yourself what you're gaining in business value out of this exercise though (I gained more focused test development with less bad crutches leading one in bad directions.  I thought I was gaining the ability not to have to install VSTT on a build box. Right now, I'm happy I did it, but not aws happy as UI was exepcting to be.

 

So, what are you hoping to gain?

Jul 1, 2009 at 8:07 AM
Edited Jul 1, 2009 at 9:57 PM
 

@ianceicys: And another thing.  You'll run into ExpectedException. I was able to transform 200 in a flash using a CodeRush template, and a CR optimise usings worked really well to clean up references.  Well worth assessing how many you have and how long its going to take you to convert them all to Assert.Throws

 

@BradWilson: Re the actual question:

VS integration is irrelevant for me as I use RedGreen or TD.NET - I'm trying to get away from MSTEST and MSTESTism.  I guess xUnit.net can make the world a better place by creating less friction for people with hard selling jobs to do, but Roy Osherove's IMHO largely misinformed post put me off for far longer.  But then I've never worked in an env rife with MSTESTism :D

GUI runner, I will prob never use (Yes I know its implemented), but the NUnit auto-reload and re-run feature is killer - to dock on another monitor.  Its easy to show to anyone that thinks they want an integrated runner.

TeamCity is done and was critical.

I'd like clean TeamBuild support though (PM me if you want to see scripts I ended up with and/or any other shortcircuiting of my last few days rantings here and on SO)

Other two, not qualified to comment

Coordinator
Jul 1, 2009 at 3:29 PM
There's not much I can do about Roy's post. New things scare people. :)

We're aware of the desire for people to be able to publish results into TFS, and although we're not going to get to that for 1.5, it's definitely on our list.
Jul 1, 2009 at 9:56 PM

Not sure if I was sub'd to Roy at the time (think I unsub'd and resub'd for a bit back then) but I, and I assume others also scanned his post and took things on board to a degree, which certainly delayed me evaluating.  Had I seen the rebuttal in time (not sure why it didnt register - I'm sub'd to your blog for ages...) I'd have wasted less time with other frameworks.  Keep up the great work and continue to be strong on keeping the core lean.

Aug 11, 2009 at 2:54 PM

Have you made any progress in the VS test runner integration?  We are looking into alternatives to the resharper test runner, especially if it is able to report on specific inlinedata test case failures.

Coordinator
Aug 11, 2009 at 3:22 PM
This will not be part of 1.5. We are talking about the possibility that this will be the primary new feature in v.Next. Part of what we've been waiting for is to see if/how the APIs will be changing in VS2010.

For people who want this feature, it would be valuable to know:

- What version of Visual Studio are you intending to run?
- How important is integration within the existing test runner UI vs. a new custom UI?
- How important is integration with TFS reporting?
Aug 12, 2009 at 10:01 AM

Re the GUI runner - I'd favor supporting 2010 over 2008.  Between RedGreen, Resharper, TD.NET and xunit.runner.gui, the bases are covered for people to get work done at 90% capacity. (The fact that the built in runner's attitude is such that it and I dont see eye to eye might have something to do with that view though)

Re TFS integration - this is a very important feature, no matter how regularly people *actually* use it - it can be make or break in the adoption decision. (If TFS ever catches up with TC on intregration of test stuff, that'll become even more obvious to people)

Mar 8, 2010 at 4:11 PM

Disclaimer:  I'm a neophyte with xUnit.net in particular and unit testing in general.

I've been comparing MSTest with xUnit.net ... I do not see direct integration of the xUnit.net 1.5 GUI in the vs2008 or vs201n IDEs as a useful benefit.

see http://bradwilson.typepad.com/blog/2009/09/xunitnet-15-shipped.html; ALT+TAB is generally more than adequate.

There's somewhat of a risk that tying the 1.5 GUI to present and future vs IDE implementations could be a crippling disadvantage to the xUnit.net GUI because Brad and Jim have demonstrated that they tend to move faster that the vs IDE team.

Although I'm relatively satisfied with the xUnit.net console runner, I do like the way the external 1.5 GUI runner works ...

         at the moment, there are THREE features that I'd like to see added to the external xUnit.net GUI runner:

(a) the ability to jump directly from the external xUnit.net GUI to a specific [Fact] method within the vs IDE;

(b) the ability to jump directly from the external xUnit.net GUI to the specific failing line of code in the [Fact] method within the vs IDE; and

(c) the ability to run one or ALL xUnit.net [Fact] methods in Debug mode, similar to the way that one initiates Test, Debug for MSTest methods.

     (c) is more necessary for tracing poorly written unit tests; well written unit tests should generally not require stepping through the unit test.


One major disadvantage of building xUnit.net into vs2008 and vs201n IDEs is that it
may leave behind those developers who are using the FREE Express versions of vs
and the lower cost Standard version of vs.


regards ~~ gerry (lowry)

Mar 9, 2010 at 4:53 PM

@ Gerry

Just wanted to say that I think (c) is already possible. If you know that a test is failing you can go into VS (I'm using 2008 Professional) and debug it. Here are the steps:

  1. Open the project properties for the project with the [Fact] you want to check in it.
  2. Go to the Debug tab.
  3. Under Start Action click the Start external program radio button and fill in the path to the console runner. (i.e. - {Path}\xunit.console.exe).
  4. Under Start Options entered the path to the compiled assembly to test. (i.e. - {Path}\bin\Debug\TestProject.dll).
  5. Save your changes.
  6. Set the project as the Startup Project.
  7. Set a breakpoint wherever if you want.
  8. Start debugging.

This didn't work for me at first even after seeing people mention to start an external program because I'm in a multi project solution and a different project was the startup project.

That being said if you your (a) request was implemented this would be much easier. After setting the project up you could run the test in the GUI, go to the failing [Fact] from there, hit your breakpoint and start debugging. It's not something I feel much need of but it could be a time-saver. ^.^

Mar 12, 2010 at 11:31 AM

@Gerry: Good to have another set of views on this.

For me, the xUnit GUI runner isnt natural to use as-is (my concerns are logged as issues).

But TD.NET just does all the above and more. I guess most people are using TD.NET and not even feeling any of this point which is why lots of people will press a vote button for it but much fewer will go in and explain their considered thoughts in full to the degree you have (i.e., the camp that really feel that pain have a solution already in TD.NET and arent waiting for xUnit.net to provide the answer).

Coordinator
Mar 12, 2010 at 3:07 PM
I love TestDriven.net. That's my primary runner (along with the MSBuild runner for automated builds).

That said, I think there are few potential things motivating the request for a Visual Studio runner for xUnit.net.

1. There are people who want something for free. TD.NET is not free.

2. There are people who want xUnit.net to "work like" MSTest, so they can convince co-workers to switch.

3. There are people who want xUnit.net to participate in Team Build, including reporting testing results to the TFS server.

(I suspect the people who fall into camp #3 are at least secondarily, perhaps primarily, doing something other than TDD with it.)
Apr 29, 2010 at 5:28 AM

Speaking for myself in regard to Team Build it is about the whole package vs. an individually item. We are doing TDD and would love to use xUnit but losing the stats that come out of the Team Build process drives us down the MSTest route.

The reason is that we are asked (rightly or wrongly) to provide stats to management teams and the sacrifices we have to make in using MSTest to be able to get stats out outweigh the issues that we have with it.

 

Oct 12, 2010 at 10:27 PM

Is this a feature that is still being considered? Our organization is currently looking into unit testing options and free Visual Studio integration is something we are very interested in. I have personal experience with xUnit.NET and really like it, however if Visual Studio integration isn't feasible without the use of third-party tools, such as TestDrive.NET or Resharper, this may be a reason for us to adopt a different unit testing framework. If this is something that you plan on working on, would you be able to provide any time estimates for when we might see it in an xUnit build?

Thanks again for making a great and versatile testing framework!

Oct 13, 2010 at 3:04 PM

It is the same in our organization. Like it or not, some people (usually key decision makers) view integration into the current tool-set a must have. I have been using xUnit.NET for a number of years now and am in love with its simplicity and how it encourages a better design for tests. However, I am facing the possibility of having to migrate all of my tests (numbering in the 1000s) over to MS Test simply due to the "appearance" of quality.

Nov 1, 2010 at 1:43 PM

Wouldn't use VS integration personally as I have R# BUT, I think for the betterment of xUnit generally, it needs to be as integrated as possible. The wider the audience the greater level of exposure, acceptance and traction it will gain.

We all know the issues with the built in stuff from MS which is why a lot of us use other tools (among other reasons) but a huge number of developers are unable, unwilling or ignorant of the options therefor any other toolset has to do *at least* what the MS version does.

Integration is essential, even if a lot of us here won't be using it.

Nov 8, 2010 at 11:50 PM

For my team and I, testing newbies running VS2010 Ultimate and using TFS, we'd really like to see a little more integration. ReSharper seems (again, newbies) to be a great test runner, but now we're looking at purchasing a code coverage tool such as dotCover (something we already paid for with our Ultimate licenses) and we still haven't figured out how to integrate our xUnit.net tests with TFS. (Yes, I've seen the posts and I know it should be possible, but TFS itself has quite a learning curve and I sure wouldn't mind if the little "run tests" checkbox just worked.) So if VS test runner integration is a precursor to working with the coverage, performance, and TFS integration we've already got then it would be at the top of our list, more so than anything else I've seen discussed here. ReSharper categories support would probably be second, but a distant second.

Hope the perspective from the small, very Microsoft, and new to unit testing crowd helps!

Thanks for the opportunity to give my input,

Drew Loika
University of Oregon

Nov 9, 2010 at 8:17 PM

Any update on this from the xUnit team? Visual Studio integration will be a deciding factor for our organization on which testing framework we will use moving forward. Here's hoping that it makes it into a future release. :)

Thanks.

Coordinator
Nov 9, 2010 at 8:40 PM
Your requests are not falling on deaf ears, but at the moment we have nothing to report.
Nov 13, 2010 at 4:20 PM

See the Support VSTS Test Runner work item for a VS2010 extension.  Be sure to read the entire comment for full details and caveats.