Ad Hoc Testing
unstructed testing type, also called random testing
1 | public class TestSort { |
JUnit Testing
org.junit library provide number of methods
- https://junit.org/junit4/javadoc/4.12/org/junit/package-summary.html
- org.junit.Assert.assertArrayEquals()
- org.junit.Assert.assertEquals()
- …
- org.junit.Test
1
2
3
4
5
6public static void testSort() {
String[] input = {"i", "have", "an", "egg"};
String[] expected = {"an", "egg", "have", "i"};
Sort.sort(input);
org.junit.Assert.assertArrayEquals(expected, input);
}
enhancements
- precede each method with @org.junit.Test
- change each test method to be non-static
- remove main method from test class
- by adding import
- import org.junit.Test; change @org.junit.Test to @Test
- import static org.junit.Assert.*; omit org.junit.Assert. later in code