I am not interested in executing with MSTest.exe or via test explorer but via plain c# code (not using Process). I want a feature where external user can trigger test execution using webAPI and get back the trx results as response. I am able to achieve this with invoking MSTest.exe using Process object. But the problem is I cannot have MSTest.exe on my web server where the webAPI (to trigger test run) is to be hosted so I cannot go ahead with Process object (or batch file execution). One possible solution I thought is if there is any dll or nuget package which allows to execute test cases with similar arguments as passed to MSTest.exe (like test project dll, category etc) then I need not to have MSTest.exe on my web server instead I can invoke that dll, get the results and return them. But I am not sure whether there is any such dll or nuget package.
Asked
Active
Viewed 176 times
-1
-
Unit tests are just methods, you can run them like any other method. But why would you want to do this? – DavidG Jun 06 '18 at 11:51
-
1Possible duplication: https://stackoverflow.com/questions/1564681/running-vsts-tests-without-mstest-exe – Prasad Telkikar Jun 06 '18 at 11:52
-
A question like this can only be properly answered with more contextual information such as what you would like to do and what you hope to achieve. Help us to help you. – JayV Jun 06 '18 at 12:11
-
Updated problem description, please share if there is a solution. – Punit Jain Jun 07 '18 at 05:52
2 Answers
0
With that little info you gave:
Yes, there is a way, you can create a .bat
file to excute a Target
inside a Project file. Or you can execute them directly from the cmd or powershell.
"msbuild" yourproject.proj /target:RunTest

Nekeniehl
- 1,633
- 18
- 35
-
I updated the problem description, please go through it and let me know if you have a solution – Punit Jain Jun 07 '18 at 05:48
0
With NUnit test framework it is possible, so instead of using MSTest I switched to NUnit.
ITestEngine engine = TestEngineActivator.CreateInstance();
TestPackage package = new TestPackage("path/to/assembly");
ITestRunner runner = engine.GetRunner(package);
XmlNode result = runner.Run(this, TestFilter.Empty);
Add nuget packages 'nunit.engine.api' and 'nunit.engine' in order to use this. Class making these calls is assumed to implement ITestEventListener.

Punit Jain
- 1
- 2