May 15, 2021 jUnit
In order to set up JUnit with eclipse, you need to follow these steps.
Download JUnit
Operating system | Filename |
---|---|
Windows | junit4.10.jar |
Linux | junit4.10.jar |
Mac | junit4.10.jar |
Let's say you copied the above JAR file in the C:;JUnit folder.
Now your eclipse is ready for the development of the JUnit test case.
/*
* This class prints the given message on console.
*/
public class MessageUtil {
private String message;
//Constructor
//@param message to be printed
public MessageUtil(String message){
this.message = message;
}
// prints the message
public String printMessage(){
System.out.println(message);
return message;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
String message = "Hello World";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testPrintMessage() {
assertEquals(message,messageUtil.printMessage());
}
}
The following is the project structure
Finally, verify the output of the program by right-clicking the program and run as junit.
Verify the results