Category: JUnit
Introduction to JUnit Theories
A normal test captures the intended behavior in one particular scenario, given an input it expects a certain output. A theory captures some aspect of the intended behavior in possibly infinite numbers of potential...
Running Parameterized JUnit Tests
The Parameterized test runner allows you to run a test many times with different sets of parameters. To run a test class with the Parameterized test runner, you must meet the following requirements. The...
Learning JUnit Assumptions with Assume
Sometimes our test fails due to an external environment configuration or a date or time zone issue that we don’t have control over. We can defend our tests by using the org.junit.Assume class. This...
Executing JUnit tests in Order
By design, JUnit does not specify the execution order of test method invocations. The JUnit runner depends on reflection to execute the tests. The JVM does not specify any particular order and could be...
Aggregating JUnit Tests in Test Suites
Using Suite as a runner allows you to build a suite containing tests. To create a suite, annotate a class with @RunWith(Suite.class). To add test classes to that suite, annotate the same class and...
Verify Behaviour of your services with Mockity verify()
In this example we explain how to use Mockito verify to verify complex behaviour of our services. Here is a list of what we can verify: Verify some behaviour Stub expected values Verifying exact...
Initialize Mockito Tests with JUnit
This example show you how to initialize mockito tests using annotations. First we can use the MockitoAnnotations.initMocks(this) method to explicitly initialize the annotated mocks. The MockitoJUnitRunner JUnit runner uses the MockitoAnnotations.initMocks(this) method to initialize...
JUnit Ignore Test using @Ignore Annotation
Suppose we have some failing unit test because of a system reconfiguration or a change of client requirements or even a developer wrote some bad tests and he is currently on vacation. But we...
JUnit Timeout for Test Method Execution
This tutorial shows how the JUnit Timeout works. You can specify a timeout in JUnit, this means that when a test execution is longer than the specified timeout the test method will fail automatically...