Right now I have both type of tests but when I say \"mvn test\" it only executes TestNG tests and not Junit. I want to execute both one after another. Any Idea ?
I found out a solution to run both test types with TestNG without changing your build tool configuration.
I tested with Gradle but should work with Maven too.
Note that this will run JUnit tests inside TestNG, but not the other way back.
The trick is to use both frameworks' annotations in the test classes and use TestNG asserts for JUnit compatibility.
import static org.testng.AssertJUnit.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@org.testng.annotations.Test
public final class ApplicationTest {
@org.testng.annotations.BeforeClass
@BeforeClass
public static void setup () {}
@org.testng.annotations.AfterClass
@AfterClass
public static void cleanup () {}
@Test public void json () throws IOException {
assertTrue (true);
}
}
Using this hack, you can easily run existing JUnit tests with TestNG, helping you migrate them when time allows.
Hope it helps!