how to assign a test file in resharper? - nunit

how to assign a test file in resharper?
whenever I select 'run tests' it says no test file found.
I created a test project, how do I link it?

I've only done minimal work with NUnit and Resharper, but the way I've always done it is just write all of the test code in your test project, and link/include the library you want to test using using statements. Make sure to include the [TestFixture] and [Test] attributes in your test classes, and when you select "Run Unit Tests" in VS on your test project, it should go through each [TestFixture] class and run all of the [Test] functions.
All that being said, I have found that running nunit tests in Resharper (v3.1 at least) to be less than ideal. It does not recognize some test conditions such as ExpectedException, so I always run my tests directly in NUnit itself.

Related

NUnit TestDirectory wrong when running tests from multiple TestProjects in NUnit Runner

I'm using VS 2013 and NUnit.
I'm running my tests in Resharpers's TestRunner GUI - this thing:
I have multiple projects (Solution.Foo, Solution.Bar, etc), and tests for each project in Solution.Foo.Tests, Solution.Bar.Tests, etc.
One of my tests in Foo.Tests is accessing a file, located in the Solution.Foo.Tests Folder.
I use TestContext.CurrentContext.TestDirectory to locate it and when I run that test it all works just fine.
If I run the whole suite of tests in Foo.Tests, (i.e. click on Solution.Foo.Tests in the Runner GUI and run) then it's fine.
But if I select one test from Bar.Tests and my file-reading test from Foo.Tests, then it fails, because suddenly TestDirectory is set to a path in Bar.Tests.
It's as if NUnit set TestDirectory once when it starts running a collection of tests, determined by where the first test is and then never updates it again.
Any ideas what's going on and how to fix it?
ReSharper has an optimisation for speed, by sharing an AppDomain across multiple assemblies. The downside to this is that it will pick an arbitrary assembly to be the main one, which means the directory can be wrong (and it might not pick up the correct app.config, too).
You can disable the optimisation in ReSharper → Options → Unit Testing, by checking the "Use separate AppDomain for each assembly with tests".

Resharper shows all tests of a text fixture are passed but text fixture fails

I'm using resharper with nunit. As seen in the picture all test are passed in a text fixture but text fixture fails. All my test cases are parameterized by the way. How does this happen?
When I click on the text Fixture it says: Failed:Child test failed
I downloaded nunit installer and run the test with nunit GUI. nunit showed 2 failed tests. I fixed them and now resharper shows it right. Looks like it is a bug with resharper 6.

How to Integrate NUnit With VS 2008

Hi i created a unit test case using NUnit.When i run the test NUnit it works fine.But i need to run it by using Visual studio.So i referred the NUnit website and followed the below steps
1)Right clicked the test project and clicked properties |Chose Debug option
2)checked the external program option and choosed the nUnit exe file.
3)And i run the test
Error i got:
Cannot start because the test project does not contain any test method.But i included 4 test methods which works in NUnit GUI.
Thanks in advance
Check out TestDriven.NET, a free Visual Studio add-in that allows you to run your unit tests with NUnit directly from the IDE.
Also ReSharper beautifully supports testing with NUnit!
http://www.jetbrains.com/resharper/features/unit_testing.html
On the Debug options tab, make sure to also set a command line argument with the name of your test assembly.

Create NUnit test cases automatically from Pex

I need to create the NUnit Test case automatically from my .Net Solution file.
Morover this needs to be done , from command line.
I heard Pex create test cases automatically.
Let know
The following steps should get you there:
Add a reference to Pex.NUnit.dll in your test project
In your test project's AssemblyInfo.cs, add the attribute - [assembly: Pex.NUnit.PexNUnitPackage]
Build your solution (either from Visual Studio or using msbuild from the command line)
run Pex from the command line: pex.exe bin\Debug\TestProjectName.dll
The tests are placed under reports\TestProjecName.#####.#####\tests.
You can read more about this in Exercise 5 of Parameterized Unit Testing with Microsoft Pex
Ryan Gross' answer
points to the right direction.
However Pex.exe generates Unit Tests from Parameterized Unit
Tests, not from
application classes itself.
To generate Parameterized Unit Tests you need to run pexwizard.exe
pexwizard.exe <your assembly name> options
Possible options are described in
http://testoriented.googlecode.com/svn-history/r89/suitability/trunk/Tools/Pex-0.22.50128.1/pexwizard.txt

Is it possible to have MSpec & NUnit tests in a single project?

I've got a unit test project using NUnit. When I add the mspec (machine.specifications) assembly to the references, both ReSharper and TestDriven.Net stop running the NUnit tests and only run the mspec tests.
Is there a way or setting that allows both NUnit & mspec tests to co-exist and run in the same project using R# & TD.Net test runners?
I've just tested this on VS 2008 with ReSharper 5.0 and TestDriven.Net 3.0 RC2 and the following code.
using Machine.Specifications;
using NUnit.Framework;
namespace ClassLibrary1
{
[TestFixture]
public class FooTests
{
[Test]
public void Bar()
{
Assert.IsTrue(true);
}
}
public class When_tests_are_run
{
It should_succeed = () => true.ShouldBeTrue();
}
}
I cannot reproduce the behavior you describe with the ReSharper. First off, ReSharper detects both test classes as indicated by the green-and-yellow gutter marks. Right-clicking on the project and selecting "Run Unit Tests" runs both tests successfully. Running them individually via the gutter icons also works as expected.
As for TestDriven.Net, I'm not sure whether it supports scenarios where multiple test frameworks are used within one project. When I "Run Test(s)" on the project, only the MSpec context is executed. However, "Run Test(s)" while clicking inside the NUnit TestFixture executes the NUnit test.
Make sure you turn on MSpec in ReSharper. Even if you "installed" the runner (by hand or by bat file), it's not turned on by default. Turn it on at
ReSharper menu | Options... | Tools | Unit Testing