Showing posts with label Junit. Show all posts
Showing posts with label Junit. Show all posts

Monday, January 14, 2019

Hello World Parameterized Junit Test

In this article we will see how to build a Parameterized Junit Test.

Parameterized tests was introduced with JUnit 4. Basic concept of Parameterized tests is to run the same test over and over again using different inputs.

There are 4 steps involve in this -

  • Annotate the test class with @RunWith(Parameterized.class)
  • Create a public static method annotated with @Parameterized.Parameters that returns a Collection of Objects as test data set
  • Create a public constructor that takes input as a single data item from step 2
  • Create an instance variable for each item of test data


Lets see the example -

Created a maven project as shown below -


pom.xml

HelloWorld.java

HelloWorldTest.java

Saturday, October 6, 2018

Java - Cucumber Hello World example

In the previous article we have seen JBehave Hello World example. In this article we will see same Hello World example but with using Cucumber.

Like JBehave, Cucumber is also used for behavior-driven development (BDD) testing. To know more about Cucumber click here.

Below is the eclipse folder structure -


Sunday, August 5, 2018

JBehave Hello World example (Eclipse + Maven + JUnit)

JBehave is a framework for Behaviour-Driven Development (BDD). To know more about JBehave, click here.

Below is the eclipse folder structure -



Please create a maven project and add the following files -


Wednesday, July 25, 2018

Simple junit test case with mockito

Mocking is a way to test the functionality of a class in isolation. Mockito facilitates creating mock objects seamlessly. It uses Java Reflection in order to create mock objects for a given interface. Mock objects are nothing but proxy for actual implementations. To know more about mockito, click here.

Maven dependiencies

This is simple junit testing, we will see integration testing in a different article.

Greeting.java
This is the Greeting.java class for which we are writing junit test cases

GreetingTest.java