### CLASSPATH - environment variable for JAVA setenv CLASSPATH .:/home/accounts/COURSES/cs475/common-files/junit-4.5.jar:$CLASSPATH
Now type
source ~/.cshrcand if no errors, it should display nothing.
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import junit.framework.JUnit4TestAdapter;
/**
* Some simple tests.
*
*/
public class SimpleTest {
protected int fValue1;
protected int fValue2;
@Before public void setUp() {
fValue1= 2;
fValue2= 3;
}
@Test public void testAdd() {
double result= fValue1 + fValue2;
// forced failure result == 5
boolean check = (result == 6);
assertEquals("5 and 6 are not the same", false, check);
}
@Test(expected = java.lang.ArithmeticException.class)
public void testDivideByZero() {
int zero= 0;
int result= 8/zero;
}
@Test public void testEquals() {
assertEquals("12 equals 12", true, (12 == 12));
assertEquals("12L equals 12L", true, (12L == 12L));
Long l1 = new Long(12);
Long l2 = new Long(10);
boolean check = l1.equals(l2);
assertEquals("Long(12) doesn't equal Long(10)",
false, check);
}
// Need to call the JUnit runner
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(SimpleTest.class);
}
}
javac SimpleTest.java
java org.junit.runner.JUnitCore SimpleTestUse the -ea option if you have asserts.
java -ea org.junit.runner.JUnitCore SimpleTest
false to
true, i.e.,
before change
assertEquals("5 and 6 are not the same", false, check);
after change
assertEquals("5 and 6 are not the same", true, check);
Observe what happens.
cp ~cs475/public_html/2008-2009/code/junit/latitude/*.java .
cp -r ~cs475/public_html/2008-2009/code/junit/money .
scriptin electronic form and in printing form.