4

In VS2010 you can specify multiple startup projects (right-click on Solution & selelct appropriate options in the "Startup Project" area).

That works fine if you hit F5, but for NUnit tests I haven't yet found a way to startup those projects before running the tests. Is there a way?

Constraints:

  1. I don't want to run the console apps from dos, as I want debug support.

  2. I don't want to have a seperate solution open. My Reasoning here is just that there's a little more friction switching between solutions & making sure edits go in the right solution. VS2010 does a good job of checking when files have changed, but, it'll just be easier to have one integrated debug experience that works the same way as when hitting F5.

Currently I'm using NUnit with Resharper 6.

Hopefully there's an option somewhere that I'm missing.

Thanks for taking a look at this.


UPDATE:

So it looks like an unsupported situation at the moment. Presently I'm looking at starting the tests as console applications as well. Probably I'll create way of secifying one test or all tests manually.

It'd be nice to be able to get a report on success/failure even if run outside of the test runner. Is it back to doing this manually?

A SOLUTION

Pedro posted these links in the comments to solution posts:

For these files in *C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0*:

  • nunit.exe.config

  • nunit-x86.exe.config (IMPORTANT FOR ME)

I made these settings changes:

Under <configuration> add:

    <startup>
      <supportedRuntime version="v4.0.30319" />
    </startup>

and under <runtime> add:

    <loadFromRemoteSources enabled="true" />
Community
  • 1
  • 1
sgtz
  • 8,849
  • 9
  • 51
  • 91
  • The whole point of creating a Unit test is to test a piece of code as a single unit without any dependency. If there are dependencies, you can use Mock. – Asdfg Aug 04 '11 at 14:05
  • What is the purpose of the console app you're starting up? It seems to be that if you have a dependency on something else you could well be outside the boundaries of what a "unit test" is supposed to do. – DoctorMick Aug 04 '11 at 14:05
  • @Asdfg: okay it's not a unit test then. Integration testing? – sgtz Aug 04 '11 at 14:08
  • @DoctorMick: testing the consumption of services provided by a message bus. A console app represents a particular publisher in a pub / sub pattern. – sgtz Aug 04 '11 at 14:10
  • You dont do Integration tesing using NUnit. At least i dont do. – Asdfg Aug 04 '11 at 14:10
  • As per your comments, you have dependency on Publisher and you may want to create a Mock object of it. – Asdfg Aug 04 '11 at 14:14
  • @Asdfg: I'm doing some Mock type things in a few places. This need is a little different – sgtz Aug 04 '11 at 16:32

3 Answers3

2

In another question, I posted a solution for running the NUnit GUI simply by pressing F5. If you then set the unit tests and console app projects to both run, you should get the desired outcome.

Community
  • 1
  • 1
Pedro
  • 12,032
  • 4
  • 32
  • 45
  • +2 (one on each post!). I'm going to take a look now. ty. – sgtz Aug 04 '11 at 16:14
  • I tried that. I'm getting an error from NUit "System.BadImageFormatException... You may be attempting to load an assembly built with a later version of the CLR" That's true. This is a ver. 4 image. – sgtz Aug 04 '11 at 18:00
  • Are you building a 32-bit or 64-bit assembly? My guess is your test assembly doesn't match the correct NUnit GUI. In your NUnit install directory, you should have both nunit.exe and nunit-x86.exe. You will need to select the one that matches the test assembly. – Pedro Aug 04 '11 at 18:13
  • Yep. That was it. A few things. It's a little slow to boot up nunit, and also, getting a 'the breakpoint will not currently be hit' message. Can't attach to the nunit-x86 process either. – sgtz Aug 04 '11 at 20:12
  • If the breakpoint can't be hit, NUnit is probably kicking off a second process. Here are a couple posts that should help: http://stackoverflow.com/questions/3542904/nunit-2-5-7-requires-explicit-debug-attach-under-vs2010 and http://stackoverflow.com/questions/930438/nunit-isnt-running-visual-studio-2010-code – Pedro Aug 04 '11 at 20:47
1

According to this page, NUnit has a [TestFixtureSetUp] attribute that will run once before running any other unit tests. While I haven't used NUnit myself, I would think you should be able to launch any necessary prerequisite programs in a method tagged with this attribute. As the code is executed just like any other, I would think it could be debugged like any other block of code as well.

Shaun Hamman
  • 2,287
  • 4
  • 21
  • 33
  • TestFixtureSetUp is mostly used for creating Unittest data or define global variables or Mock objects. You dont launch console Apps in there. – Asdfg Aug 04 '11 at 14:12
  • 1
    @Asdfg Don't/Can't or shouldn't? While I would agree that Mocking is probably the most correct thing to do, if there is a reason someone doesn't want to do that I see no reason this wouldn't be an alternative. – Shaun Hamman Aug 04 '11 at 14:15
  • You are defeating the whole purpose of Unit Testing by creating real time dependency in that. No one will stop you from doing it but if for some reason your Pulisher stops working, your Unit test case will fail even though you dont care if Publisher is working or not as it is not in the Unit test scope. – Asdfg Aug 04 '11 at 14:20
  • Okay. I agree on the scoping issue for the definition of a unit test. However, clearly in this case I think it's important to increase the scope. – sgtz Aug 04 '11 at 14:27
1

Since you are using Resharper as your test running, I'm curious if you have tried something along these lines. Set your solution's startup projects to be the console application(s) you want, and press F5. Then, right-click on the test project/file that you are interested in running and then click 'Run Unit Tests.'

It looks like Resharper hides the 'Debug Unit Tests' option while the solution is the running state, but if you are looking to debug the console app side of things, this might work for you (totally untested theory at this point). I would assume you would be out of luck debugging the test side of things though using this method.

And of course this is tied to Resharper's test runner, if you were looking to do this on a continuous integration build system or via the NUnit GUI/Console, this method wouldn't even come close to helping you out.

ckittel
  • 6,478
  • 3
  • 41
  • 71
  • +1 Not a bad idea. That is likely to work I think for signalled apps I think. So I will probably alternate between Resharper which has a faster startup time, and the nunit config settings (see accepted answer). – sgtz Aug 05 '11 at 07:14