Tag Archives | junit

Assertions in JUnit

Assertions are what JUnit is all about. The code you are testing is doing something. Your assertions will test that after running the software under test with a certain set of inputs, you will have a specified output. assertArrayEquals() The assertArrayEquals() method will test whether two arrays are equal to each other i.e. they have [...]

Continue Reading ... Comments { 0 }

Parameterized Unit Test with JUnit 4

Junit 4 has introduced a new feature Parameterized tests. These tests allow developer to run the same test many times using different values. To mark a test class as a parameterized test, you must first annotate it with @RunWith(Parameterized.class). The class must then provide at least three entities: A static method that generates and returns [...]

Continue Reading ... Comments { 0 }

TestSuite with JUnit

Junit provides a way to test any number of tests together. @RunWith and @Suite annotation are used to run the suite test. Following example demonstrates how to use Test Suit. Create following class

Continue Reading ... Comments { 0 }

JUnit – Expected Exception Test

Junit provides a way to test whether code throws desired exception or not. Following example demonstrates Excepted Exception Test using JUnit. First create a new Java Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml Test Passed Create following class Now when you run the project, following [...]

Continue Reading ... Comments { 0 }

JUnit – Timeout Test

If a test case takes more time than specified number of milliseconds then Junit will automatically mark it as failed. Following example demonstrates Timeout Test using JUnit. First create a new Java Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. JUnit Class Create following class [...]

Continue Reading ... Comments { 0 }

JUnit – Ignore Test

Sometimes, it is required not to execute any testcase. So by using @Ignore annotation, you can bypass any testcase. Following example demonstrates how to ignore a testcase. First create a new Java Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. JUnit Class Create following class [...]

Continue Reading ... Comments { 0 }

JUnit Testing using Annotation

A JUnit test fixture is a Java object. With older versions of JUnit, fixtures had to inherit from junit.framework.TestCase. Now with JUnit 4 Test methods must be annotated by the @Test annotation. Table 1.1 Annotations in JUnit 4.x. Annotation Description @Test public void method() The annotation @Test identifies that a method is a test method. [...]

Continue Reading ... Comments { 0 }

Unit Testing with JUnit

This article describes basic test writing using JUnit. First create a new Java Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. POJO Create following class 2. JUnit Class Create following class 3. Testing Now when you run the project, following screen will be displayed if [...]

Continue Reading ... Comments { 0 }