How to pass parameters to xunit unit tests ran through the console runner? - xunit

The NUnit console runner has the -p command line parameter which is used to pass parameters to the test.
It seems that XUnit suggests us to drop dead in this respect or read the parameters from the environment.
Do I understand it correctly or am I missing anything? If this is correct, what is the motivation?

Related

how to publish automation test result in MTM while using TFS 2017?

I am setting up Test agents as part of build definition and now I want to run automation test case using TCM.exe, How can I pass the Test Environment name as an argument?
In TFS 2013 I did something like this-
start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tcm.exe" -ArgumentList " run /create /title:Nightly Run /planid:1334 /suiteid:123 /configid:123456 /settingsname:Test_xyz_TestSettings /testenvironment:xyzFuntional /collection:http://xyz:8080/tfs/ppp /teamproject:aa /include"
because in 2013 we were setting test controller and test agent as part of lab management and we knew the name of the test environment.
My requirement is to publish automation result in MTM ,any other way is really appreciated .Please note i can not use Test Hub for Test result publishing.
Thanks
Based on your screenshot, you are using the Run functional Test but not TCM.exe.
VStest, MStest and TCM.exe are different tools (Refer to this thread for more info.).
The tests in your scenario supposed to be used to associate test runs with builds and actually using vstest. MTM is displaying test results that are associated with test plans/suites which are somewhat independent of builds.
You can try to use tcm.exe to get what you're after. It's a command line interface to running tests, similar to mstest, but it runs the tests through the infrastructure you set up in MTM. Here's the documentation page: http://msdn.microsoft.com/en-us/library/dd465192.aspx
However, you can also try to follow the steps mentioned in below link to publish the VStest or MStest test results to MTM :
Uploading automated test results to MTM made "easy"
Use TCM to upload the resulting TRX file
Note There is problem with VSTS (formerly VSO) that causes these automated tests to stay in a state of “In Progress”*
Sample TCM command line:
TCM run /publish /suiteid:ID# /configid:CONFIG# /resultowner:"USER" /resultsfile:"C:\DLL\testResults.trx" /collection:"TFS_COLLECTION_URL" /teamproject:"PROJECT_NAME"
UPDATE:
The infrastructure (e.g. Test Environment you mentioned here ) is set in MTM, If you run the test with tcm.exe, generally it will pick up the parameters automatically. But if run test with VSTest or MStest the parameters may need to be defined with Set up environments to run continuous test tasks with your build tasks ...
Whatever, based on your description I think below articles should helps:
Continuous Delivery with VSO: Executing Automated Web Tests with
Microsoft Test Manager
Continuous Delivery with TFS: Running Automated Web Tests with
MTM

Mocha tests in browser to output xunit reports

I'm running a set of tests with mocha and i need the tests to run in the browser, therefore ; i'm doing this :
mocha.setup('bdd')
the tests do run fine in the browser, but i need this to be executed in jenkins. I must run the tests in the browser and i'm trying to get the reporter to output xunit reports .
i've tried the xunit-file package and another one called "mocha-multi" , it looks like browser tests only support the html reporter. Is there a way to output both the xunit and browser reports? or at least to execute the tests in the browser and report xunit results?
so there is no way to have two reporters if you're running the tests in the browsers and not in node js. After digging into mocha,i realized that there is a tests results variable as part of the mocha objects that you can instantiate in the browser. You need to use this to actually access the resutls and write the report yourself.

Running MSTest tests from C#

Is it possible to run all tests of a TestClass class using C# code only ? I found that it is possible to run tests using a command line tool called MSTest, but this is not what I am looking for.
I want to run all tests defined in a class, change some parameters and run all tests again. This would be repeated a few times, so it would be nice to do it using C#, as it would be easy to evaluate the test results programmatically.

How do I run a specific test within junit

We have several junit test cases in a particular file, how do I run a certain test alone.
Note: I am aware of the #Ignore annotation, but don't want to use it. Since you will still have to mark the rest of the use cases with the #Ignore option.
You can specify the test you would like to run via the -Dtest= parameter.
Just run it with this parameter values:
-Dtest=TestClass#singleTestCaseMethod
It is only supported in JUnit 4.x. More information: Running a single test
This depends on how you're running the tests.
If you're using Eclipse, you can either select the name of the method in the Java Editor and press F11/ctrl-F11 to Run As JUnit. This also works if the cursor is on the method name itself.
If you've already run the tests, and the JUnit view is open in Eclipse, you can rerun a particular method by right clicking on the test and selecting Run/Debug. There will be similar functionality in Intellij.
If you're running from the command line, you can use JUnitCore.
java org.junit.runner.JUnitCore TestClass1 TestClass2
EDIT: For maven, you can specify the name of the method on the command line:
mvn -Dtest=TestCircle#mytest test
See the documentation for Maven Surefire - Running a Single Test.
In IntelliJ (You should try the free community edition, I tried several IDE and I found IntelliJ to be the best, far ahead the competition), you press CtrlshiftF10 to run unit tests. The location of the cursor will decide what to run: if it's within a test, it will run this test only, if it's outside, it will run all the tests on the current class.
And shiftF10 will re-run whatever was last ran.
You can also right-click on the Run view to re-run any specific test.

MSTest /noisolation fails tests

If I use MSTest with the parameter /noisolation my tests fail, but without it they pass.
If I run MSTest without the parameter for the first time a ms office configuration box appears and configures something because my tests depend on excel. this happens only the first time. then the test runs trough without problems.
but if I run my test with the parameter the box doesn't appear and tests fail.

Resources