You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the described scenario works fine: the test case compiles and runs successfully. Yet, the warning persists, it does not affect the execution.
What does not work
But there will be an error if I generate a test suite, then add any class/method/function in my file under test and try to use the newly created construct in any test case. I will get the following error:
Steps to reproduce:
Generate a test suite for a class CalcKotlin in the following file:
internalclassA {
val a ="123"
}
classCalcKotlin {
val a =10;
funadd(a:Int, b:Int): Int {
return a + b
}
}
Suppose the following test case is generated:
classGeneratedAddNegativeNumbersTest {
privateval calc =CalcKotlin()
@Test
funaddNegativeNumbersTest() {
val result = calc.add(-5, -10)
assertEquals(-15, result)
}
}
Now, add a creation of A and an assert for its value, it should execute successfully:
classGeneratedAddNegativeNumbersTest {
privateval calc =CalcKotlin()
@Test
funaddNegativeNumbersTest() {
val result = calc.add(-5, -10)
assertEquals(-15, result)
val a =A()
assertEquals("123", a.a)
}
}
Now, add the class B into the file under test:
internalclassA {
val a ="123"
}
classB { // added this class; notice that it is public!val b ="1"
}
classCalcKotlin {
val a =10;
funadd(a:Int, b:Int): Int {
return a + b
}
}
Now, instantiate this class in the test case:
classGeneratedAddNegativeNumbersTest {
privateval calc =CalcKotlin()
@Test
funaddNegativeNumbersTest() {
val result = calc.add(-5, -10)
assertEquals(-15, result)
val a =A()
assertEquals("123", a.a)
val b =B()
// optional:
assertEquals("1", b.b)
}
}
Execute the test case and see the error as in the image above.
Vladislav0Art
changed the title
[Kotlin] Package directive does not match file location
[Kotlin] Package directive does not match file location & test cases do not see modifications in the file under test
Oct 8, 2024
Describe the bug
How it works for Java
The following java class
is located in
/private/var/folders/pm/<>/T/testSparkResults/test_gen_result_<>/org/tests/GeneratedMethodPublicInvokesPrivateTest.java
And the IDEA see that the package name and the location (the suffix of the path) matches. So we can have the proper access to the package elements.
How it works for Kotlin
The following kotlin class
is located in
/private/var/folders/pm/<>/T/testSparkResults/test_gen_result_<>/org/example/GeneratedConstructorPrimaryNameOnlyTest.kt
But IDEA shows me the warning: Package directive does not match the file location. So we have the problem with access.
For example, we can not access, so the compilation for all tests of this class will fail.
The text was updated successfully, but these errors were encountered: