generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
Testing
brianneoberson edited this page Dec 5, 2023
·
1 revision
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class nameOfClassThatsToTestTests{
@Test
fun nameOfFunctionThatsToTest_nameOfTestDataSetThatsUsed() {
// Arrange
val a = 3
val b = 5
// Act
val result = a + b
// Assert
assertEquals(8, result, "Addition failed: $a + $b should be 8")
}
}
There are several ways to access test data:
- Using Hardcoded Data:
@Test
fun testAddition() {
val a = 3
val b = 5
val result = a + b
assertEquals(8, result, "Addition failed: $a + $b should be 8")
}
- Using External Configuration Files:
@Test
fun testAddition() {
val testData = loadTestData("testdata.json")
val result = testData.a + testData.b
assertEquals(testData.expectedResult, result, "Addition failed")
}
- Using Test Fixtures and Factories
@Test
fun testAddition() {
val testData = TestDataFactory.createTestData()
val result = testData.a + testData.b
assertEquals(testData.expectedResult, result, "Addition failed")
}
For further information concerning testing see: IntelliJ - Testing