We help IT Professionals succeed at work.

Simple NUnit test doesn't run

IzzyTwinkly
IzzyTwinkly asked
on
Hi,

I am following this simple NUnit example, but it give me an error when I run it. "A project with an Output Type of Class Library cannot be started directly."
0.JPG
In the example, I created 2 projects(both are Class Library type) with a class on each project. The structure of the solution and project references look like this.
2.JPG
And this is the code I have for TellerTests.cs
3.JPG
It seems that I need a normal class that has a Main method. But I am not sure, the author brought up this screen. I don't know how.
4.JPG
I am using Visual Studio 2012 Ultimate version.

Thanks
Comment
Watch Question

Fernando SotoRetired
Distinguished Expert 2017

Commented:
Try setting the start up project to be BankManager.Test and not BankManager.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Are you using F5 to try and run your tests? If so, you shouldn't be. NUnit should have a menu option to start tests. You shouldn't need to actually start your application in order to be able run your unit tests.

Author

Commented:
Hi Kaufmed, I am using Visual Studio2012 and where can I find that Nunit menu?

Hi Fremando, I made BankManager.Test as a start up project, but nothing happened. Should I create BankManger.Test project, should I create this as "Coded UI Test Project" or "Unit TestProject"? However, the author clearly said to create it as class library. =(
Most Valuable Expert 2011
Top Expert 2015
Commented:
Have you installed the Visual Studio Test Adapter already? I *think* older versions of NUnit had a separate window to run unit tests...at least that what I remember seeing...but now they are run via the Test Explorer window that Visual Studio provides. Installing the Test Adapter should expose this to you:

 Screenshot
Once you build your project/solution, the tests should show in the Test Explorer.
Fernando SotoRetired
Distinguished Expert 2017

Commented:

Author

Commented:
That was it! I had to install "Visual Studio Test Adapter". In my case, Test Explorer itself was there, but the test method wasn't appeared under Test Explorer. Now it appears after I installed "Visual Studio Test Adapter".
Thank you so much! I just passed my first unit test!!!