Home » Core Java » junit (page 5)

junit

JUnit Test Suite Example

1. Introduction A JUnit Test suite is used to bundle multiple test cases together in a single run. This is usually used if you want to integrated several JUnit Test cases that makes up a specific functionality from the integration. The developer uses the @RunWith and @SuiteClasses to run Suite tests for this purposes. In this example, I’ll be showing a ...

Read More »

JUnit Exception Handling Example

1. Introduction There are popular ways to test exception in JUnit. A developer can use the traditional try-catch statement, the @Rule or the annotation based. In this post, I’ll be discussing these 3 simple and easy to implement ways to make your test case and functional scenarios bulletproof of incoming exceptions. 2. Source(s) In this example, we use the traditional ...

Read More »

Spring JUnit Test Example

1. Introduction Spring has it’s own testing framework for all objects created under it’s IOC container (that we all know is just the JVM instance). Spring has created it’s own paradigm of object creation and destruction and it made sense for it to have it’s own testing framework. The great thing about this is (as being Java) is it can ...

Read More »

JUnit Report Example

1. Introduction In all the test cases of an application, there is always a way to create a report of it one way or the other. JUnit is not an exception to this and there’s a ton of ways to create reports from it. It can even be incorporated to the maven site and have it part of the overall ...

Read More »

JUnit AssertThat Example

1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one. It primarily accepts 2 parameters. First one if the actual value and the second is a matcher object. It will then try to compare this two and returns a boolean result ...

Read More »

JUnit SetUp / TearDown Example

1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We needed them to be readily available when we create each of the method test cases and mock what was actually being used by the system at runtime. We can prepare this within the ...

Read More »

JUnit assertEquals example

1. Introduction To follow through with my previous post about assertTrue and assertFalse, this post will tackle on checking for an equality of a conditional statement on the test cases. There is a method called assertEquals in the JUnit library that can be used to check if two objects is equally defined or not. It can be used to check if ...

Read More »

JUnit assertFalse example

1. Introduction To follow through with my previous post about assertTrue, this will tackle about the exact opposite of that function. The assertFalse. The assertFalse is basically a function that can be used to check if a specific logic or process will return a false statement. This can be in any conditional or structural logic that will return a boolean ...

Read More »

JUnit assertTrue example

1. Introduction Every developer on every platform should always have a solid JUnit test case to secure the changes they made. This will minimise the potential risk of negativity to an existing system. There are a lot of ways to do JUnit Testing and a lot of functions available to do them. One of the most popular Unit Testing framework ...

Read More »

JUnit @Before and @BeforeClass Example

In this example we are going to explain the difference between the @Before and @BeforeClass annotations of JUnit testing framework, using Eclipse IDE. 1. Create JUnit test In this section, we will create the test case that will help us explain the difference between those annotations. Before you create the test class, it is considered as good practice to create ...

Read More »