We need to run a particular Junit Runner class with different tags one after the other . Ex : First #ATest test should run then #BTest test should run .
So the only option we have is create multiple Junit Runner . I was thinking if there would be a way to pass this as an argument from Junit Suite ?
Another approach could be to define the sequence for features in #CucumberOptions.
This wont use the tags, but will run the features from the list in the order mentioned.
Related
I'm migrating to Junit5 from 4. Can run all tests fine, single tests fine (both via the green play buttons). When I try to run tests tagged with #Tag (#Tag("foo")), it tells me that no tests are found. In the run configuration, I'm putting foo in the "Tag expressions" box, using Test kind: Tags. I've used Categories with Junit4 in the past, and Tags seem like a 1-to-1 replacement, right? I do still have some Category tags in my codebase, as I'm switching over. Several tests tagged with #Tag as well. Whether the #Category tag is present or not makes no difference in the behavior.
IntelliJ result:
Running categories [interface org.junit.Test]
Process finished with exit code 0
Use ˋorg.junit.jupiter.api.Testˋ instead of ˋorg.junit.Testˋ to run JUnit5 tests. Only those can handle the ˋTagˋ annotation.
I have defined my tests in a parametrized testng.xml. I use the Failsafe plugin and run my tests with mvn verify. The whole suite is executed.
What if I have to run only one single test from my testng.xml suite? I want that the parameters will be used, but I want to run only one test from the command line.
The maven parameter:
-Dit.test=CheckoutIT#testOrderId
does not work because maven runs the test directly without testng.xml, the parameters are not bind and the test will be ignored.
Is there a way to do it? A workaround is to create a temporary suite xml with only one test but it can't be a solution...
Best regards Robert
According to testng doc:
The command line flags that specify what tests should be run will be ignored if you also specify a testng.xml file, with the exception of -includedgroups and -excludedgroups, which will override all the group inclusions/exclusions found in testng.xml.
Another solution is to add listener to your maven goal which will parse your testng.xml and get test parameters to apply them to your current test.
How can I find tests that have not been added to a test suite?
If I run the test suite I get say 1000 tests but if I run a file search for "#Test" I get 1020 results. How can I go and add the missing ones without having to go through every search result and comparing to the tests that ran to see which ones are missing?
Use Eclipse itself to create a test suite. From the context menu of the project, select 'New -> Other' and select JUnit test suite. It will list out all the test classes in the project. By default, it creates a AllTests.java source file.
I am currently working on a Maven Project, using JUnit for defining tests and Jenkins for CI and am looking into how I can group my tests.
Say I had a test class with 20 tests, but I don't want to run all 20 tests, I want to be able to configure which tests to run. For Example, in another standalone project using TestNG and Selenium you can create a test method with the following annotation:
#Test (groups = { "AllTest" })
public void myTestMethod()
{
.. do something
.. assert something
}
... and then I am able to call which group to run based on an XML configuration.
Is it possible to define such type of groupings using Jenkins? I have researched into this and came across the plugin "Tests Selector Plugin" however can't understand how to get started once I've installed the plugin. There is a Wiki Page for it but I can't understand what to do after installing.
I have copy pasted the example property file, and didn't really understand what I needed to manipulate in it. When building, I simply get that the property file cannot be found or Jenkins doesn't have permission; can't find a way around this either :(
It's possible via maven + maven-surefire-plugin
http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
You can run a single test, set of tests or tests by regexp.
Is it no option to exclude some tests in IntelliJ IDEA Ultimate? I want to run unit tests in IntelliJ but exclude the integration tests. I name the integration tests with *IT.java so the Maven failsafe plugin can run them seperatly from the unit tests.
In the JUnit Run configuration set the Test kind to Pattern, specify the following regular expression as the pattern:
^(?!.*IT$).*$
It matches against the class name, so you don't need to match .java extension. Regular expression will not match if the class name ends with IT using the negative lookahead.
With JUnit5, you can now tag your tests, e.g: #Tag("integration-test").
Also, given IntelliJ supports now JUnit5 as well, you can then create a JUnit Test Configuration and select Test Kind: Tags (JUnit5).
To exclude let's say "integration-test", you just need to specify as tags:
!integration-test, and IntelliJ will run all your JUnit5 tests except the ones tagged with integration-test.
I would split them to that they are in different packages. They are doing different things after all. You can then run your tests per package. This link details how to do this.