简体   繁体   中英

How do I get Visual Studio's test window to use my ITestContainerDiscoverer?

I'm trying to write a test adapter for Visual Studio 2013 (I'm running Premium with Update 1, and have the VS SDK in, so I could reference all of the VS DLLs). Because it will work off raw content files and not compiled dll/exe's, it seems I need to create an ITestContainerDiscoverer .

I've found a number of public repos online that appear to have implemented these; eg:

TypeScript , Json , Node , and many more

However; my code appears to be same (and the same references to VS DLLs), yet never seems to fire. I've put File.Write, Console.WriteLine, Debuuger.Launch, and also attached another VS instance to it. Here's what my class currently looks like:

[Export(typeof(ITestContainerDiscoverer))]
public class MyTestContainerDiscoverer : ITestContainerDiscoverer
{
    [ImportingConstructor]
    public MyTestContainerDiscoverer([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
    {
        File.WriteAllText(@"M:\Coding\Applications\LuaTestAdapter\LuaTestAdapter\bin\Debug\Danny.txt", "TEST!");
        Console.WriteLine("IT'S RUNNING!");
        Debugger.Launch();
    }

    public Uri ExecutorUri
    {
        get { return TestExecutor.ExecutorUri; }
    }

    public IEnumerable<ITestContainer> TestContainers
    {
        get
        {
            return new[] {
                new TestContainer(this, @"M:\TestProject\Test.lua")
            };
        }
    }

    public event EventHandler TestContainersUpdated;
}

I'm building this in a DLL that ends with .TestAdapter.dll and manually copying it into C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow\\Extensions and then launching VS. The TestAdapter is being correctly loaded by VS, because in the same project my TestDiscoverer (which currently includes DLL as an extension for debugging) is outputting to the console:

[FileExtension(".lua")]
[FileExtension(".dll")]
[DefaultExecutorUri(TestExecutor.ExecutorUriString)]
public class TestDiscoverer : ITestDiscoverer
{
    public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
    {
        logger.SendMessage(TestMessageLevel.Informational, "This one works!");
    }
}

So I presume it must be something wrong with the TestContainerDiscovered; but I just can't see anything in the samples I found online doing anything differently :O(

Looks like I might have found the difference... If I create a Visual Studio Package project and install my TestAdapter "the old way", then my code executes fine.

It looks like "normal" TestAdapters (eg. those using compiling DLLs/EXEs and therefore can use the provided TestContainerDiscoverers) work fine (this is why NUnit, xUnit etc. can work with NuGet based packages, or copying the DLLs into the Extensions folder), but to get mine to work, I needed it to be installed via a Package project with the following "Asset" included (presumably because of the use of MEF to wire up the ITestContainerDiscoverer).

<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="LuaTestAdapter" Path="|LuaTestAdapter|" />

It seems that by default Visual Studio only find test discoverers in .exe and .dll .

So, when you want to extend (eg .lua ) you need to implement these two interfaces as well:

  • ITestContainer
  • ITestContainerDiscoverer

And also the standard ones:

  • ITestDiscoverer
  • ITestExecutor

To test if it will run, you can execute this command:

cd Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow

vstest.console.exe /listdiscoverers /useVsixExtensions:True

If it outputs something like this:

打字稿testadapter

It means your discovers are being loaded. Since it is a new one with different file extension I guess you can't just copy the files, I guess it needs to be installed.

When I created this adapter I copied everything from this example provided by Microsoft and modified it. Make sure your vsixmanifest looks the same etc...

Besides examples, I didn't find any actual documentation...

Hope this helps somehow...

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