How can I create NUnit tests using ReSharper?

I am trying to get into unit testing with C #. Various people have told me to go with NUnit, since it is better than MSTest (apparently I have no idea), and it also has very good support in the ReSharper that I use.

Now I have never written unit test in my life (carry me, I am a university student). ReSharper has this nice CreateUnitTests context menu menu that I've seen when others (casually looking over their shoulders) use for great success. You right-click in the method, select CreateUnitTests, and there you go, a test skeleton is created. You just fill in the important bits.

Now when I try to do the same, ReSharper wants me to create a new test project ... and when I enable it, it creates (what I suppose) an MSTest project with an explicit MSTest test template. But I already have a libarary project class that references "nunit.framework" and has several NUnit tests that ReSharper is more than ready to run. However, he only ever creates MSTest test patterns and only ever in special Project Projects.

What am I doing wrong? Am I doing something wrong or creating NUnit test templates that cannot be used with ReSharper? I searched the net and read the documentation of ReSharper and NUnit, and I still cannot figure out if this is possible or what.

I would be grateful if anyone could provide me with guidance on using ReSharper + NUnit.

EDIT: I am using ReSharper 4.5 and NUnit 2.5.3

EDIT2: Apparently, I'm an idiot. CreateUnitTests is not part of ReSharper, but it is part of Visual Studio and therefore only works with MSTest.

+7
c # unit-testing nunit resharper
source share
2 answers

In the test project that Resharper created, remove the link to the testing module for the Microsoft DLL module (I don’t remember the name from my hand, but this is a rather long name).

Then add a new link - nunit.framework.dll, you should find it on the first tab of the "Add Link" dialog.

Add using NUnit.Framework to the unit test class file.

Then you need to change the attributes:

 [TestClass] to [TestFixture] [TestMethod] to [Test] 

So, if you finish the MSTest project, use the steps above to get NUnit.

NOTE. Resharper 4.5 onwards has built-in support for running MSTest, as well as NUNit tests. So you can try this.

+12
source share

You do not need to run any wizards to use NUnit. You can simply create a class library, add a link to NUnit, and mark your tests with the appropriate attribute. Wizards are only for MSTest and even then, are not required.

After completing unit tests, the ReSharper test runner will detect them, and in the left field you will get several icons that will allow you to run / debug tests. See the first image here for an example:

NUnit and ReSharper

+5
source share

All Articles