Created
May 25, 2011 07:21
-
-
Save eranharel/990501 to your computer and use it in GitHub Desktop.
A calculator class example Junit 4 test case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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