Refactored the test names and used backtick identifiers.

This commit is contained in:
Ali Dehghani 2019-02-01 12:00:43 +03:30
parent 191039ffc6
commit 8d9d76cc09
2 changed files with 7 additions and 6 deletions

View File

@ -7,12 +7,12 @@ class CalculatorTest5 {
private val calculator = Calculator() private val calculator = Calculator()
@Test @Test
fun whenAdding1and3_thenAnswerIs4() { fun `Adding 1 and 3 should be eqaul to 4`() {
Assertions.assertEquals(4, calculator.add(1, 3)) Assertions.assertEquals(4, calculator.add(1, 3))
} }
@Test @Test
fun whenDividingBy0_thenErrorOccurs() { fun `Dividing by zero should throw the DivideByZeroException`() {
val exception = Assertions.assertThrows(DivideByZeroException::class.java) { val exception = Assertions.assertThrows(DivideByZeroException::class.java) {
calculator.divide(5, 0) calculator.divide(5, 0)
} }
@ -21,7 +21,7 @@ class CalculatorTest5 {
} }
@Test @Test
fun whenSquaringNumbers_thenCorrectAnswerGiven() { fun `The square of a number should be eqaul to that number multiplied in itself`() {
Assertions.assertAll( Assertions.assertAll(
Executable { Assertions.assertEquals(1, calculator.square(1)) }, Executable { Assertions.assertEquals(1, calculator.square(1)) },
Executable { Assertions.assertEquals(4, calculator.square(2)) }, Executable { Assertions.assertEquals(4, calculator.square(2)) },
@ -76,7 +76,7 @@ class CalculatorTest5 {
Tag("logarithms") Tag("logarithms")
) )
@Test @Test
fun whenIcalculateLog2Of8_thenIget3() { fun `Log to base 2 of 8 should be equal to 3`() {
Assertions.assertEquals(3.0, calculator.log(2, 8)) Assertions.assertEquals(3.0, calculator.log(2, 8))
} }
} }

View File

@ -5,15 +5,16 @@ import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class SimpleTest5 { class SimpleTest5 {
@Test @Test
fun whenEmptyList_thenListIsEmpty() { fun `isEmpty should return true for empty lists`() {
val list = listOf<String>() val list = listOf<String>()
Assertions.assertTrue(list::isEmpty) Assertions.assertTrue(list::isEmpty)
} }
@Test @Test
@Disabled @Disabled
fun when3equals4_thenTestFails() { fun `JUnit should complain and report failed assertions`() {
Assertions.assertEquals(3, 4) { Assertions.assertEquals(3, 4) {
"Three does not equal four" "Three does not equal four"
} }