28

I'm trying to get started writing unit tests in a project. I wrote the createTest first and tried it. This test passed and I started writing my other tests.

Now all my tests just say "Test not run". This happens both when I try to run all tests at once and when I run a single test.

https://github.com/Requinard/OperationOctopus/tree/UnitTest

All I've found so far is people using NUnit. We're using the default microsoft testing framework, with resharper running the tests.

    [TestMethod]
    public void CreateTest()
    {
        Init.Initialize();
        // set up
        UserModel user = new UserModel();

        user.Address = "Testing Street 1";
        user.Email = "Testing@test.com";
        user.Level = 2;
        user.Password = "test";
        user.RfiDnumber = "00d0wad0aw";
        user.Telephonenumber = "0638212327";
        user.Username = "testcaseuser";

        Assert.IsTrue(user.Create(), "Cannot write user to database");

        test_user = user;
    }

    [TestMethod]
    public void ReadTest()
    {
        Init.Initialize();
        // set up
        UserModel user = getTestUser();

        Assert.AreEqual(user.Email, test_user.Email, "Reading returned an unexpected result");
    }

    [TestMethod]
    public void AlterTest()
    {
        Init.Initialize();
        UserModel user = getTestUser();

        user.Email = "test@testing.com";

        Assert.IsTrue(user.Update(), "Failure during updating");

        user.Read();

        Assert.AreNotEqual(user.Email, test_user.Email);
    }

    [TestMethod]
    public void DestroyTest()
    {
        Init.Initialize();
        UserModel user = getTestUser();

        Assert.IsTrue(user.Destroy(), "Could not destroy user");
    }

The above tests will make resharper say "Test not run"

I just tried running the tests on my laptop. They worked without any changes to the code and the test completed instantly. This leads me to think I'm dealing with a faulty config somewhere.

requinard
  • 921
  • 1
  • 11
  • 24
  • 1
    Please include relevant code in the question itself. – Pierre-Luc Pineault Apr 13 '15 at 19:43
  • Try running in debug and step through to see what is happening. – Jacob Roberts Apr 13 '15 at 20:19
  • I set a breakpoint at the first statement of CreateTest() and ran debug. Visual studio started loading a load of symbols and then promptly stopped my debugging session. – requinard Apr 13 '15 at 20:23
  • It also seems that the tests work fine on my laptop, just not on my desktop – requinard Apr 13 '15 at 20:31
  • 1
    Make sure the ReSharper copy on your desktop is set to enable the MSTest provider, in ReSharper Options -> Unit Testing. It's enabled by default, but if you check in your ReSharper files to Git, another developer may have disabled it for the small performance boost, under the assumption you'e be using NUnit. – KeithS Apr 13 '15 at 21:14
  • The MSUnit provider is enabled. I'm starting to think that there is something wrong with my desktop, as my laptop will actually perform the tests without any problems. – requinard Apr 13 '15 at 21:50
  • I've just removed R# and rebooted. The problem still persists. My tests are not running at all. The problem is isolated to my desktop – requinard Apr 13 '15 at 21:56

7 Answers7

48

I think restarting the whole system may have been a little premature. I have found when this happens all you need to do is restart Resharper.

I usually do this from the Command Window in Visual Studio , you just need to type these commands one after the other

Resharper_Suspend
Resharper_Resume

this generally fixes the problem for me and doesn't require reopening the solution.

If this fails you can clear the resharper caches. Information can be viewed here on how to do that.

here is how to do it from VS menu

BastanteCaro
  • 1,269
  • 1
  • 13
  • 24
  • 2
    I did this via the Visual Studio options menu. Worked! – willem Sep 14 '17 at 06:44
  • Thank you @BastanteCaro .. Resharper can be a pain – Mike Oct 13 '17 at 13:13
  • Here's how to do it via Visual Studio Options menu: https://stackoverflow.com/questions/2189792/how-can-i-disable-resharper-in-visual-studio-and-enable-it-again – Eternal21 Jun 20 '18 at 16:16
  • Clearing caches worked for me, where I wasn't even seeing the "tests not run" message - the test sessions pane was just empty! – Paul Aug 02 '18 at 16:04
6

Make sure you aren't doing what I was doing and completely forget that solution is in release mode with test project set to build only in debug mode ;-)

Ted
  • 7,122
  • 9
  • 50
  • 76
6

There was a bug in ReSharper 2017.3.1, which was fixed in 2017.3.2: https://blog.jetbrains.com/dotnet/2018/02/01/resharper-ultimate-2017-3-2-bugfix/

You can update using ReSharper > Help > Check for Updates.

You can see if you had the same error by enabling logs. This is what I had:

--- EXCEPTION #2/2 [LoggerException]
Message = “Passed version string '2.1.101' doesn't look to be a valid .net core sdk version”

And eventually:

|W| UnitTestLaunch | System.NullReferenceException: Object reference not set to an instance of an object.
at JetBrains.ReSharper.UnitTestProvider.nUnit.v30.NUnitServiceProvider.GetRunStrategy(IUnitTestElement element)
at JetBrains.ReSharper.UnitTestProvider.nUnit.v30.Elements.NUnitElementBase.GetRunStrategy(IHostProvider hostProvider)
at JetBrains.ReSharper.UnitTestFramework.Launch.Stages.BuildStage.CollectProjectsToBuild()
at JetBrains.ReSharper.UnitTestFramework.Launch.Stages.BuildStage.Run(CancellationToken token)
at JetBrains.ReSharper.UnitTestFramework.Launch.UnitTestLaunch.RunStage(Object stageObject)

My project is using NET471, and I run ReSharper 2017.3.1 in Visual Studio 15.6.27428.2005

Christian Rondeau
  • 4,143
  • 5
  • 28
  • 46
  • I don't know if this is the problem that I had, but restarting Re-sharper did not help, but installing a new version did, so perhaps that's what it was. – Eternal21 Jun 20 '18 at 16:30
  • Problem for me was that the unit test project contained a reference to Microsoft.AspNetCore.App of which I didn't have the corresponding SDK version installed. This makes the resharper unit tests hang without any error. Only when I turned on the resharper verbose logging, I found out it was due to the dotnet core sdk version. – Tincan Oct 03 '18 at 07:00
  • ughhh thank you for posting this. i lost a few hours of productivity just because I didn't update resharper! – Mash Feb 02 '19 at 00:10
4

This also happened to me, and found the reason in here: http://www.henrikbrinch.dk/Blog/2012/02/15/Making-Resharper-testrunner-work-in-64-bit

This fix is actually harsh, and what I did is change the configuration: VS2015 -> Resharper -> Options -> Unit Testing -> Default platform architecture - Force tests to run in 32-bit process

Hope this will help you

daviddv
  • 177
  • 7
2

I periodically run into this because I work on a project with multiple branches and switch between them without shutting down Visual Studio. This will occasionally confuse ReSharper and I will no longer have the NUnit options on some projects.

In Visual Studio Community 2017 with ReSharper 2018.2 the first thing I try is to Unload the project where the NUnit test runner is not available. Sometimes that is the only needed step.

Next I use ReSharper->Options->General->'Clear caches' which requires a VS restart.

Then I unload and reload the misbehaving project again.

This fixes the issue.

Naylor
  • 752
  • 7
  • 20
1

Happened to me today and none of the above suggestions (clearing cache, restarting VS, suspend/resume of resharper) worked.

However in the Unit Test Sessions tab under Error I could see I had a TypeLoadException which allowed me to pinpoint the problem. enter image description here

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
-7

It seems there was a bad config /somewhere/. I reinstalled the entire sysetm, followed by VS2013 and R#. The tests now run fine.

requinard
  • 921
  • 1
  • 11
  • 24
  • 7
    Reinstalling an entire system isn't a possible solution for most people. – bak202 Dec 08 '15 at 18:10
  • 1
    @bak202 true, true. A better way is to look at all the logs. This way of solving problems is actually a big problem and an impediment to learning. @Samyn do not be afraid to approach lots of logs and solve the problem in 'developer`s style' :) Reinstalling a system wastes your time. Taking on the logs forces you to run. – Ognyan Dimitrov Jan 25 '16 at 08:43
  • 4
    scorched earth to kill a fly. – joelmdev Mar 23 '17 at 15:55
  • 1
    You should've bought a new computer instead, just to be safe :) – Eternal21 Jun 20 '18 at 17:00
  • Well whaddaya know, I recently did get a new job and lo-and-behold after a month I ended up with the same issue. This was still the only answer that worked – requinard Jun 24 '18 at 17:25
  • I suspect just installing Resharper would have made the trick – Sergioet Aug 08 '18 at 08:00