JUnit Tutorial
Introduction to Junit JUnit Set up JUnit Architecture JUnit Annotations JUnit Fixtures Junit Assertions Junit Categories @Test Annotation Parameters Verification of Exceptions Ignoring tests Time out in JUnit tests Parameterizing tests Test Suite TestWatcher TemporaryFolder ExternalResource Theories in JUnit JUnit Test Runners Execution order of JUnit tests Assumptions in JUnit JUnit and Hamcrest Matchers Running JUnit tests in parallel JUnit and Maven Integration JUnit and Gradle Integration Executing Selenium tests using JUnit test framework Method interceptor and usage JUnit in Intellij IDEA JUnit in EclipseTest runners in junit
In this topic, let us learn about various test runners available to run JUnit tests.Using IDE
All popular IDEs like Eclipse, IntelliJ IDEA, Net beans provide plug-ins to run JUnit tests from within IDE.Using command line
We can also run the tests from command line using below syntax.
java org.junit.runner.JUnitCore MyTestClass1 MyTestClass2 MyTestClass3
Using runClasses method of JUnitCore class
We can also run JUnit tests using JUnitCore class. This class provides a method called as runClasses to which we can pass list of classes to be run. In below example, tests from 2 test classes will be run – OrderedTests and HamcrestTests.
package runners;
import hamcrest.TestHamcrest;
import ordered_tests.OrderedTests;
import org.junit.runner.JUnitCore;
/**
* Created by Sagar on 30-04-2016.
*/
public class JunitRunners {
public static void main(String [] args){
JUnitCore.runClasses(OrderedTests.class, HamcrestTests.class);
}
}
Using custom Runners
We can also have custom runners as well created using @RunWith annotation. For example, popular BDD framework cucumber uses custom runner to run JUnit tests using @RunWith annotation.Web development and Automation testing
solutions delivered!!