-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCalculatorTest.java
More file actions
37 lines (31 loc) · 801 Bytes
/
CalculatorTest.java
File metadata and controls
37 lines (31 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.github.stokito.unitTestExample.calculator;
import junit.framework.Assert;
import org.junit.Test;
public class CalculatorTest {
@Test
public void testSum() {
// Given
Calculator calculator = new Calculator();
// When
int result = calculator.sum(2, 2);
// Then
if (result != 4) { // if 2 + 2 != 4
Assert.fail();
}
}
@Test
public void testMinus() {
Calculator calculator = new Calculator();
Assert.assertEquals(0, calculator.minus(2, 2));
}
@Test
public void testDivide() {
Calculator calculator = new Calculator();
Assert.assertEquals(2, calculator.divide(6, 3));
}
@Test(expected = ArithmeticException.class)
public void testDivideWillThrowExceptionWhenDivideOnZero() {
Calculator calculator = new Calculator();
calculator.divide(6, 0);
}
}