Java by API/org.junit/Test
Версия от 17:43, 31 мая 2010; (обсуждение)
org.junit.Test
import static org.junit.Assert.assertTrue;
import junit.framework.JUnit4TestAdapter;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Some simple tests.
*
*/
public class Main{
public static void main (String... args) {
junit.textui.TestRunner.run (suite());
}
@BeforeClass public static void setUpOnce() {
System.out.println("@BeforeClass: set up onece");
}
@Before public void setUp() {
System.out.println("@Before: set up ");
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(Main.class);
}
@Test public void testCopy() {
assertTrue(1 == 1);
}
}
Test.expected()
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import junit.framework.JUnit4TestAdapter;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
public class MainClass{
public static void main (String... args) {
junit.textui.TestRunner.run (suite());
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(MainClass.class);
}
@Test (expected=IndexOutOfBoundsException.class) public void elementAt() {
int[] intArray = new int[10];
int i = intArray[20]; // Should throw IndexOutOfBoundsException
}
}