8

I am very new to unit testing. I have been following the procedures for creating a unit test in visual studio 2012 on http://channel9.msdn.com/Events/TechEd/Europe/2012/DEV214.

The test just won't start. And it will prompt me "A project with an Output Type of Class Library cannot be started directly.

In order to debug this project, add an executable project to this solution which references the library project. Set an executable project as the startup project.

Even though I attached the unit test class code to a console program, the test does not start and the test explorer is empty. In the video, it doesn't need to have any running program. The lady only created a class library, and the test will run.

what should I do? Note. there is no "create unit test" on the mouse right click menu

enter image description here

Hoy Cheung
  • 1,552
  • 3
  • 19
  • 36
  • 1
    Please take a look at this post: http://stackoverflow.com/questions/16214684/why-is-the-xunit-runner-not-finding-my-tests?rq=1 this should resolve your issue. – SOfanatic May 01 '13 at 14:06
  • Hi, changed the method to static and public, but still no test is shown on test browser. I have attached a screen. Any clue? – Hoy Cheung May 01 '13 at 16:45
  • it's a code library project. And it doesn't matter whether I create a unit test project or not, Visual Studio just doesn't include any test in my xunit file. I have created a MSTest unit, which turns out fine. – Hoy Cheung May 01 '13 at 20:14
  • I'd like to add that the version of XUnit retrieved by NuGet must be the stable 1.9 version. If you use XUnit2 (which is the only Xunit visible if prerelease is selected in NuGet) then VS'12 will not see your tests even if you install the xunit runner via the VS Tool gallery. – Robbie May 31 '13 at 18:09

3 Answers3

12

I found out the reason why. I have to go to Visual Studio Gallary and download xUnit.net runner and the tests will get into my test explorer. Just getting the library from Nuget won't do the work.

Hand-E-Food
  • 12,368
  • 8
  • 45
  • 80
Hoy Cheung
  • 1,552
  • 3
  • 19
  • 36
5

The runner found in Visual Studio Gallary is no longer supported. You should use the NuGet packages:

Install-Package xunit.runner.visualstudio

Install-Package xunit.runner.msbuild

Install-Package xunit.runner.console
Ricardo Valente
  • 581
  • 1
  • 10
  • 14
0

Since you are using xunit what you have to do, if you want to run your tests from VS, is map the Xunit console to VS as an external tool. Details here: Can Visual Studio 2010 Test Runner run XUnit?

Otherwise you can install TestDriven.net from here: http://www.testdriven.net/download.aspx and this will allow you to right click on your test project and run the tests.

As a side note: don't forget to build your solution before trying to run any tests.

Community
  • 1
  • 1
SOfanatic
  • 5,523
  • 5
  • 36
  • 57
  • thanks a lot! I have just added xunit.console.exe to VS2012. And I click xUnit Test under my TOOLS manual. But the Output window prompts me 'Could not load file or assembly 'E:\My Documents\programming\exercise\xunit\xunit\bin\Debug\xunit.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.' – Hoy Cheung May 01 '13 at 20:39
  • You probably have the wrong version, in your nuget consolo type `Uninstall-Package xunit` to uninstall your current version, and then `install-package xunit -version 1.9.1` to install the latest non-beta version. – SOfanatic May 01 '13 at 22:25