Updated test names (#2856)

This commit is contained in:
Graham Cox 2017-10-26 03:30:53 +01:00 committed by KevinGilmore
parent 080af1cb45
commit 6ac536861e
2 changed files with 12 additions and 12 deletions

View File

@ -7,12 +7,12 @@ class CalculatorTest5 {
private val calculator = Calculator()
@Test
fun testAddition() {
fun whenAdding1and3_thenAnswerIs4() {
Assertions.assertEquals(4, calculator.add(1, 3))
}
@Test
fun testDivideByZero() {
fun whenDividingBy0_thenErrorOccurs() {
val exception = Assertions.assertThrows(DivideByZeroException::class.java) {
calculator.divide(5, 0)
}
@ -21,7 +21,7 @@ class CalculatorTest5 {
}
@Test
fun testSquares() {
fun whenSquaringNumbers_thenCorrectAnswerGiven() {
Assertions.assertAll(
Executable { Assertions.assertEquals(1, calculator.square(1)) },
Executable { Assertions.assertEquals(4, calculator.square(2)) },
@ -31,9 +31,9 @@ class CalculatorTest5 {
@TestFactory
fun testSquaresFactory() = listOf(
DynamicTest.dynamicTest("1 squared") { Assertions.assertEquals(1,calculator.square(1))},
DynamicTest.dynamicTest("2 squared") { Assertions.assertEquals(4,calculator.square(2))},
DynamicTest.dynamicTest("3 squared") { Assertions.assertEquals(9,calculator.square(3))}
DynamicTest.dynamicTest("when I calculate 1^2 then I get 1") { Assertions.assertEquals(1,calculator.square(1))},
DynamicTest.dynamicTest("when I calculate 2^2 then I get 4") { Assertions.assertEquals(4,calculator.square(2))},
DynamicTest.dynamicTest("when I calculate 3^2 then I get 9") { Assertions.assertEquals(9,calculator.square(3))}
)
@TestFactory
@ -44,7 +44,7 @@ class CalculatorTest5 {
4 to 16,
5 to 25)
.map { (input, expected) ->
DynamicTest.dynamicTest("$input squared") {
DynamicTest.dynamicTest("when I calculate $input^2 then I get $expected") {
Assertions.assertEquals(expected, calculator.square(input))
}
}
@ -59,14 +59,14 @@ class CalculatorTest5 {
@TestFactory
fun testSquaresFactory3() = squaresTestData
.map { (input, expected) ->
DynamicTest.dynamicTest("$input squared") {
DynamicTest.dynamicTest("when I calculate $input^2 then I get $expected") {
Assertions.assertEquals(expected, calculator.square(input))
}
}
@TestFactory
fun testSquareRootsFactory3() = squaresTestData
.map { (expected, input) ->
DynamicTest.dynamicTest("Square root of $input") {
DynamicTest.dynamicTest("I calculate the square root of $input then I get $expected") {
Assertions.assertEquals(expected.toDouble(), calculator.squareRoot(input))
}
}
@ -76,7 +76,7 @@ class CalculatorTest5 {
Tag("logarithms")
)
@Test
fun testLogarithms() {
fun whenIcalculateLog2Of8_thenIget3() {
Assertions.assertEquals(3.0, calculator.log(2, 8))
}
}

View File

@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test
class SimpleTest5 {
@Test
fun testEmpty() {
fun whenEmptyList_thenListIsEmpty() {
val list = listOf<String>()
Assertions.assertTrue(list::isEmpty)
}
@Test
@Disabled
fun testMessage() {
fun when3equals4_thenTestFails() {
Assertions.assertEquals(3, 4) {
"Three does not equal four"
}