Category: Testing

junit tutorials

JUnit Exception Testing

Testing code that throws exceptions is as important than testing only the happy path. It may be even more important. Luckily JUnit provides us with a basic toolkit to verify if an exception is thrown....
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 the...
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 scenarios....
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 test...
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 class...
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 random....
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 add...