You saw how to use the TestRunner class in the Introduction. You can create a folder called "hw1" for this assignment and keep all the relevant files in that folder. Upload the file "MyUtilTest.java" and a snapshot of the output produced when running the "TestRunner" class .
For this assignment we have a "MyUtil" class .
File: "MyUtil.java"
public class MyUtil
{
public String getFullName( String firstName, String lastName)
{
return ( firstName +" " + lastName ) ;
}
}
This has a single method that concatenates the 2 strings in the argument to return a single string.
Write a "MyUtilTest.java" class that tests this method with 2 tests. The first test has the first name as "Joe" and the last name as "Louis" . The second method tests the method with the first argument as "Joe" and the second argument as null. Even though our method "getFullName" looks correct it does not define what to do when one or both arguments are null . We are going to assume that "Joe" and a null as the last name will produce a failed case for us. The first test case will be a success case.
Run your "MyUnitTest.java" using the "TestRunner" class .
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner
{
public static void main(String[] args)
{
Result result = JUnitCore.runClasses(MyUtilTest.class);
for (Failure failure : result.getFailures() )
{
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}