Category: Testing

junit tutorials

I/O Testing with JUnit TemporaryFolder Rule

The TemporaryFolder rule facilitates the creation and deletion of files and or folders. You can easily create a new file/folder using the TemporaryFolder#newFile() method. The file or folder is guaranteed to be deleted after...
junit tutorials

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...
junit tutorials

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...
junit tutorials

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...
junit tutorials

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...
junit tutorials

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...
mockito tutorials

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 tutorials

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...