質問

Simple project in Visual Studio 2012 is causing the following error when trying to load the test explorer:

------ Discover test started ------
Exception has been thrown by the target of an invocation.
========== Discover test finished: 1 found (0:00:00.152) ==========

This is my test project:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyApp
{
    [TestClass]
    public class MyTests
    {   
        [TestMethod]
        public void Test()
        {
            var foo = 1;
            Assert.AreEqual(1, foo);
        }
    }
}

The test explorer is not discovering my tests for some reason. Its probably down to the exception being raised at the top of my question. Does anyone know if this is a bug in Visual Studio 2012. Can't understand why something so simple is blowing it up?!?

役に立ちましたか?

解決

After installing SP3 for Visual Studio 2012, the error seemed to disappear.

他のヒント

I too faced same problem, but for Selenium tests, which uses NUnit adapter to discover them in test explorer window. In test explorer it was giving same error 'Exception has been thrown by the target of an invocation.' I thought there might be some problem with the NUnit Adapter extension which is responsible to discover tests, but it was not, as a different project(solution), which was not under TFS, was able to discover all the tests.

The inner exception would have given better idea of the problem, but I was not able to see that in any way. So tried various options and tried same solution on different machines which were able to discover and run tests without any problem.

After all my analysis and google, I came to know the problem was because of TFS, somewhere either on mappings, or something else, something messed up there for that particular machine.

This blog was really helpful.

What worked for me: I tried different options mentioned on above blog except uninstalling VS (2012). However creating the new TFS work-space and getting the project on fresh new location under the new workspace worked for me. While doing so, i also reset all the user settings, 3rd option mentioned on the blog.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top