简体   繁体   English

如何让Visual Studio的测试窗口使用我的ITestContainerDiscoverer?

[英]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). 我正在尝试为Visual Studio 2013编写测试适配器(我正在使用Update 1运行Premium,并且安装了VS SDK,因此我可以引用所有VS DLL)。 Because it will work off raw content files and not compiled dll/exe's, it seems I need to create an ITestContainerDiscoverer . 因为它将解决原始内容文件而不是编译的dll / exe,所以我似乎需要创建一个ITestContainerDiscoverer

I've found a number of public repos online that appear to have implemented these; 我在网上发现了一些似乎实施了这些的公共回购; eg: 例如:

TypeScript , Json , Node , and many more TypeScriptJsonNode 等等

However; 然而; my code appears to be same (and the same references to VS DLLs), yet never seems to fire. 我的代码似乎是相同的(和VS DLL相同的引用),但似乎永远不会触发。 I've put File.Write, Console.WriteLine, Debuuger.Launch, and also attached another VS instance to it. 我放了File.Write,Console.WriteLine,Debuuger.Launch,还附加了另一个VS实例。 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. 我在一个以.TestAdapter.dll结尾的DLL中构建它,并手动将其复制到C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow\\Extensions ,然后启动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: VS正确加载TestAdapter,因为在同一个项目中,我的TestDiscoverer(当前包含DLL作为调试扩展)正在输出到控制台:

[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; 所以我认为TestContainerDiscovered一定有问题; but I just can't see anything in the samples I found online doing anything differently :O( 但是我在网上发现的样本中看不到任何不同的东西: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. 看起来我可能已经发现了差异......如果我创建一个Visual Studio Package项目并以“旧方式”安装我的TestAdapter,那么我的代码执行正常。

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). 它看起来像“普通”TestAdapters(例如那些使用编译DLL / EXE,因此可以使用提供的TestContainerDiscoverers)工作正常(这就是为什么NUnit,xUnit等可以使用基于NuGet的包,或者将DLL复制到Extensions文件夹中),但为了让我的工作,我需要通过包含以下“资产”的Package项目安装它(可能是因为使用MEF连接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 . 似乎默认情况下,Visual Studio只能在.exe.dll找到测试发现者。

So, when you want to extend (eg .lua ) you need to implement these two interfaces as well: 因此,当您想要扩展(例如.lua )时,您还需要实现这两个接口:

  • ITestContainer ITestContainer
  • ITestContainerDiscoverer ITestContainerDiscoverer

And also the standard ones: 还有标准的:

  • ITestDiscoverer ITestDiscoverer
  • ITestExecutor 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. 当我创建这个适配器时,我从Microsoft提供的这个例子中复制了所有内容并进行了修改。 Make sure your vsixmanifest looks the same etc... 确保你的vsixmanifest看起来一样......

Besides examples, I didn't find any actual documentation... 除了例子,我没有找到任何实际的文件......

Hope this helps somehow... 希望这有助于某种方式......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ITestContainerDiscoverer在Visual Studio 2015中不起作用 - ITestContainerDiscoverer not working in Visual Studio 2015 如何让我的 Selenium 测试在 Visual Studio 中运行? - How can I get my Selenium test to run in Visual Studio? 如何使用Visual Studio项目中包含的文件? - How do I use a file included in my visual studio project? 有没有办法在我自己的应用程序中使用Visual Studio的“监视窗口”? - Is there a way to use Visual Studio's Watch Window in my own App? 如何将发电机代码导入Visual Studio? - How do I get my dynamo code into visual studio? 如何修复 Visual Studio 的测试资源管理器中的“活动测试运行已中止”? - How do I fix “The active test run was aborted” in Visual Studio's Test Explorer? C# byte[] 中的前 8 个字节是什么,如何在 Visual Studio 的内存窗口中跳过它们? - What are the first 8 bytes in a C# byte[] and how do I skip them in Visual Studio's memory window? 如何在Visual Studio 2017中使用“C#Interactive”窗口查询“数据连接”中的源代码 - How can I use, in Visual Studio 2017, the “C# Interactive” window to query a source in my “Data Connections” 如何让我的控制台窗口停止让我在Visual Studio中输入? - How do I make my console window stop making me type enter in Visual Studio? Visual Studio:如何让我的测试项目启动它依赖的Web项目 - Visual Studio: How can I get my test project to start the web project it depends on
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM