Source Code : Set JUnit Test case fail information
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Set JUnit Test case fail information
import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class MainClass extends TestCase {
public static void main (String... args) {
junit.textui.TestRunner.run (suite());
}
public MainClass(String name) {
super(name);
}
public void testPassNullsToConstructor() {
try {
Person p = new Person(null, null);
fail("Expected IllegalArgumentException because both args are null");
} catch (IllegalArgumentException expected) {
}
}
public void testNullsInName() {
fail("sample failure");
Person p = new Person(null, "lastName");
assertEquals("lastName", p.getFullName());
p = new Person("Tanner", null);
assertEquals("Tanner ?", p.getFullName());
}
public static void oneTimeSetup() {
System.out.println("oneTimeSetUp");
}
public static void oneTimeTearDown() {
System.out.println("oneTimeTearDown");
}
public static Test suite() {
TestSetup setup = new TestSetup(new TestSuite(MainClass.class)) {
protected void setUp() throws Exception {
oneTimeSetup();
}
protected void tearDown() throws Exception {
oneTimeTearDown();
}
};
return setup;
}
}
class Person {
private String firstName;
private String lastName;
public Person(String firstName, String lastName) {
if (firstName == null && lastName == null) {
throw new IllegalArgumentException("Both names cannot be null");
}
this.firstName = firstName;
this.lastName = lastName;
}
public String getFullName() {
String first = (this.firstName != null) ? this.firstName : "?";
String last = (this.lastName != null) ? this.lastName : "?";
return first + " " + last;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
}
Thank with us