Memorynotfound Java Programming 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...
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...
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...
Serializing and Deserializing Enums using GSON
By default Gson serializes enums by name in lowercase. If this is not sufficient and you want some other stirng or an integer value, then have a look at the @SerializedName annotation. Gson can...
Gson Tree Model Write and Parse to and From JSON
Gson Tree Model API provides support to read and parse a JSON String into a Tree Model. We can use the JsonParser to parse the JSON string into a Tree Model of type JsonElement....