Skip to content

Instantly share code, notes, and snippets.

@eranharel
Created May 25, 2011 07:21
Show Gist options
  • Save eranharel/990501 to your computer and use it in GitHub Desktop.
Save eranharel/990501 to your computer and use it in GitHub Desktop.
A calculator class example Junit 4 test case
public class CalculatorTest {
private Calculator classUnderTest;
@Before
public void setUp() throws Exception {
this.classUnderTest = new Calculator();
}
@After
public void tearDown() throws Exception {
classUnderTest = null;
}
@Test
public void testAdd_positiveNumbers_shouldReturnResult() {
assertEquals("add", 7, classUnderTest.add(3, 4));
}
@Test(expected = IllegalArgumentException.class)
public void testAdd_negativeNumbers_shouldThrowException() {
classUnderTest.add(-3, -4);
}
@Test
public void testSubstract() {
assertEquals("substract", 2, classUnderTest.substract(5, 3));
}
@Test
public void testMultiply() {
assertEquals("multiply", 56, classUnderTest.multiply(7, 8));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment