How to create and install test adapter in Visual Studio

雨燕双飞 提交于 2019-12-03 09:02:56

The documentation is very poor for creating test adapter for VS. There are many URL that can help to understand how implement UTE with JS automated test :

In summary :
Step 1 :

  • we need to implement ITestExecutor to launch test with protractor prompt command and return the result.
  • we need to implement ITestDiscoverer to parse file in argument to find all tests inside.

You can test this primary version without VSix : Go to Visual studio Test extension folder (C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions for VS 2013) and add your DLL and dependencies. Try to launch tests with commands like that in windows command prompt :

cd C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow  
vstest.console.exe "c:\test\test.js"

Step 2 :
By default Visual Studio only parse .dll and .exe files. If you want to parse another file type (.lua, .js, ...) you need to create a parser who explicitly browse source files and find all tests.
You need to create implement two Interfaces :

  • ITestContainerDiscoverer
  • ITestContainer

This project (https://github.com/XpiritBV/ProtractorAdapter) will be useful to understand how implement that and how adapt your code to subscribe on any changes in your project (Add file, Edit file, Project Load, etc.).

Important : You need to create a VSix project to test that ! If not, Visual Studio don't load your TestContaineDiscoverer.

Important 2 : When you create a VSix file, you need to explain two Assets :

  • Type : Microsoft.VisualStudio.MefComponent / Path : |YourProject|
  • Type : UnitTestExtension / Path |YourProject|

Hope it's help somebody.

If you need to run the test adapter with vstest.console.exe but don't need visual studio integration you will need to do the following:

  • Create a project that is a class library
  • Very important: The assembly name must end with .TestAdapter or vstest.console.exe will not recognize your test adapter. You can change this setting in the properties of your project.
  • Import Microsoft.VisualStudio.TestPlatform.ObjectModel which for me was located at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll
  • You only need to implement ITestDiscoverer and ITestExecutor
  • If your test adapter is for .dll or .exe files the default test adapter will run first. I could not find a way to disable this.

The above accepted answer and code was very useful for me when figuring out how to create a test adapter. Be aware that if you are creating a VSIX then the asset type UnitTestExtension is not available in the list but seems to work and can be added in the .vsixmanifest file manually.

Additional useful links:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!