简体   繁体   中英

Resharper Unit Tests not running

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.

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

确保你没有做我正在做的事情,并完全忘记解决方案处于发布模式,测试项目设置为仅在调试模式下构建;-)

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

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

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. 在此输入图像描述

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM