Hi, I’m new to Kotlin and trying to get a simple test-application within IntelliJ (commiunity edition)to work.
So I created the following files:
/src/main/kotlin/com/example/calculator
Calculator.kt
package com.example.calculator
class Calculator {
fun add(a: Double, b: Double): Double {
return a + b
}
fun multiply(a: Double, b: Double): Double {
return a * b
}
}
Main.kt
package com.example.calculator
fun main() {
val calculator = Calculator()
val num1 = 5.0
val num2 = 3.0
val additionResult = calculator.add(num1, num2)
val multiplicationResult = calculator.multiply(num1, num2)
println("Addition: $num1 + $num2 = $additionResult")
println("Multiplikation: $num1 * $num2 = $multiplicationResult")
}
src/test/kotlin/com/example/calculator/CalculatorTest.kt:
package com.example.calculator
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
class CalculatorTest {
private val calculator = Calculator()
@ParameterizedTest
@CsvSource(
"1.0, 2.0, 3.0",
"-1.0, -2.0, -3.0",
"0.0, 0.0, 0.0",
"1.5, -2.5, -1.0",
"-3.0, 3.0, 0.0"
)
fun testAddition(a: Double, b: Double, expected: Double) {
assertEquals(expected, calculator.add(a, b))
}
@ParameterizedTest
@CsvSource(
"1.0, 2.0, 2.0",
"-1.0, -2.0, 2.0",
"0.0, 5.0, 0.0",
"1.5, -2.5, -3.75",
"-3.0, 3.0, -9.0"
)
fun testMultiplication(a: Double, b: Double, expected: Double) {
assertEquals(expected, calculator.multiply(a, b))
}
}
But IntelliJ keeps telling me:
/src/test/kotlin/com/example/calculator/CalculatorTest.kt:4:26 Unresolved reference: params
So what might I have done wrong?
Trying to get this working since days - even ChatGPT couldn’t help me so far.
Also I couldn’t find any tutorial (including Kotlin, IntelliJ, gradle and jUnit5) that is usefol for me as beginner