How to run Junit5 and TestNG togather in Maven pom - maven

I have some set of test cases configured with TestNG. I developed preconditions in junit5 and this has to be run before the test starts. So I wanted to run in sequence Line Precondition(junit5) and then Testcases.
I am using dependency for Junit5 and TestNG7 in PM.XML. Below is a snapshot of POM.xml htmlunitTest.java is for junit5 and testng.xml for TestNGTest cases. while running build is terminating successfully without execution of any test.

You probably do not want to hear my answer. It is the best I have anyway: Don’t take that route! Don’t couple two frameworks that are not made to work together.
Although there might be a convoluted and hacky way to achieve what you describe, you’re setting yourself up for unnecessary technical complexity. Stick with one framework and use its own means for preconditions or fixing a test order.

Related

Is there a way to enforce execution order of test classes in Junit4(5)

I am writing integration tests in a SpringBootApp with Junit5. It is a must for me to follow a execution order of REST Api calls. In one test class it is ok to use #TestMethodOrder from jUnit5 or another approach for test execution ordering in a class. My question is regard execution test classes in specific order. I found an open issue on the topic in the Junit repo https://github.com/junit-team/junit5/issues/1948 . It's not resolved. Is there a way to achieve this? I have think of #Categories introduced from Junit5 but it will be too hacky approach, it is not an option.

How to order unit test execution from Gradle?

Is there any way to specify the order of the unit tests classes run by a Gradle Test task?
I'd like to get some known longer-running tests at either the front or the back of the list, but don't know if it's possible without splitting my tests' execution between multiple tasks.
Running JUnit 4.12 and Gradle 4.5.
Gradle simply delegates execution to the JUnit runner.
So if you want specific test class ordering, you will need to create a Suite and specify the test classes in the order you want, see the JUnit documentation for this.
Now, given the flexibility of Gradle in terms of having different source roots, I would strongly recommend doing the separation at the Gradle level, by create extra test source roots, test task and the like. This will allow you to effectively control when these long running tests are run in a standard build execution, but also to skip them or run these only when desired. The ordering at the JUnit level will not give that flexibility without much more tweaking. See the Gradle documentation on adding source sets.

how is junit related to maven sure fire plugin

I am fairly new to writing Maven pom files and JUnit tests. I have following in my pom and it is calling my test scripts as expected.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
It seems JUnit is more popular than sure fire plugin.
1) How is JUnit similar/different from maven sure fire plugin's default behavior (that is working for me from above plugin configuration). I can imagine JUnit having additional API/library; but what do they give me in addition to sure fire plugin
2)what is the easiest way to change my current tests that are running with sure fire plugin to JUnit. I came across following link which sort of implies that adding few lines to pom would be sufficient (?)
http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
3)about previous bullet, what benefits would I have if I convert sure fire plugin tests to JUnit.
Hopefully, I am unambiguous (with my intro background to maven and JUnit)
maven-surefire-plugin is not itself a test framework: it's a Maven plugin that will run tests written with a test framework, either JUnit or TestNG.
I have following in my pom and it is calling my test scripts as expected.
If this is already running your tests then, as Surefire only knows about those two test frameworks, it means you're already using either JUnit or TestNG. You should be able to tell which from the classes you're importing to write your test classes.
(that is working for me from above plugin configuration)
Unless you have a particular requirement there's little reason to move away from the framework you're already using; it doesn't sound like you need to change anything.
As it says right here:
To get started with JUnit, you need to add the required version of JUnit to your project ... This is the only step that is required to get started - you can now create tests in your test source directory (eg, src/test/java).
Your question is confusing and suggests you haven't done any preliminary research yet. When you say "surefire tests" you may mean Pojo tests. If you know what a JUnit test is, it's pretty common sense thing to convert the Pojo tests to JUnit tests. Just put #Test before the Pojo test methods. You may also want to convert assert into the appropriate JUnit assert methods. In summary, just read a JUnit tutorial and the rest will be straight forward.

Maven: Conditional Execution upon IT Success / Failure

Here is something I''ve tried to come up with an idea, but I'm not sure.
We do have a module which should be built, deployed and then integration test begins (via failsafe, but others might be fine). We'd like to selectvely invoke mojos based on its results.
I think verify from failsafe should do the trick (with probably some gmaven trickery), but how to validate the results of failsafe? Perhaps some Test Listener Magic with JUnit could help?
Any ideas how could we achieve that, considering a Maven (and Probably Hudson) scenario?
Thank you
Let do the first part of that do Hudson (run integration tests) and do a failsafe:check in your integration test cycle and based on the result you can start a dependenant job in Hudson to run an other job whatever this job will do. But you can't execute selective mojos based on results (afak).

How to define dependency between tests in MStest

I have some tests which are dependent on the success and failure of some tests. How can I define dependency as I am using VS2010 Mstest and selenium.
E.g
if test1 is failed then dont run test5, test 6. is this possible.
Unit Tests should always be isolated and completly non dependent on and thing else to run, not make non-fragile.
You could setup catagories with MSTest to seperate them into deferent logical structures.
A great book to find more details is this http://artofunittesting.com
Roy has also does alot of public speaking which is recorded online
Cheers
Tests shouldn't have dependencies between them.
If you have dependencies, then running them in a different order, or in isolation will cause them to fail sporadically - this can be very confusing for anyone else that is running the tests.
It's much better to define tests that setup their own data and assert something specific. You can use a mocking framework like Rhino Mocks to reduce the dependencies between modules of code by faking (mocking) areas that aren't relevant to your test. This is made much easier if you also use a dependency injection framework like Microsoft Unity as your code will have many more seams where mocking can be applied.

Resources