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
[ x] I checked the documentation and found no answer
[ x] I checked to make sure that this issue has not already been filed
Expected Behavior
A test class T1 annotated with @MockKExtension.CheckUnnecessaryStub, which does not contain unnecessary stubbing, succeeds.
Another test class T2 without this annotation, and which contains unnecessary stubbing, also succeeds.
Both tests do not affect each other. CheckUnnecessaryStub is only applied to the annotated test class. The running order of tests does not matter.
Current Behavior
When running T1 and T2 in in this order, both tests succeed.
When running T2 and T1 in in this order, T1 fails due to the unnecessary stubbing in T2.
Steps to Reproduce
Create test file 1:
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(MockKExtension::class)
@MockKExtension.CheckUnnecessaryStub
class TestThatDoesNotAllowUnnecessaryStubbing {
@MockK
private lateinit var myObject: MyClass2
@Test
fun myTest() {
every { myObject.toString() } returns "obj as string"
Assertions.assertThat(myObject.toString()).isEqualTo("obj as string")
}
class MyClass2
}
Create test file 2:
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(MockKExtension::class)
class TestThatAllowsUnnecessaryStubbing {
@MockK
private lateinit var myObject: MyClass1
@Test
fun myTest() {
every { myObject.toString() } returns "obj as string"
}
class MyClass1
}
When running both test files in this order (e.g. via IntelliJ or Gradle), both tests succeed.
When running file2 and then file1, then the test in file1 fails:
17:16:55.263 [main] DEBUG io.mockk.impl.instantiation.AbstractMockFactory - Creating mockk for MyClass1 name=myObject#1
17:16:56.297 [main] DEBUG io.mockk.impl.instantiation.AbstractMockFactory - Creating mockk for MyClass2 name=myObject#2
17:16:56.357 [main] DEBUG io.mockk.impl.recording.states.AnsweringState - Answering obj as string on MyClass2(myObject#2).toString()
17:16:56.647 [main] DEBUG io.mockk.impl.recording.states.AnsweringState - Answering obj as string on MyClass1(myObject#1).toString()
java.lang.AssertionError: Unnecessary stubbings detected.
Following stubbings are not used, either because there are unnecessary or because tested code doesn't call them :
1) obj as string.toString())
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
MockK version: 1.13.2
OS: Windows
Kotlin version: 1.6.10
JDK version: OpenJDK 17.0.4
JUnit version: 5.8.2
Type of test: unit test
Minimal reproducible code (the gist of this issue)
see above
The text was updated successfully, but these errors were encountered:
Prerequisites
Expected Behavior
@MockKExtension.CheckUnnecessaryStub
, which does not contain unnecessary stubbing, succeeds.CheckUnnecessaryStub
is only applied to the annotated test class. The running order of tests does not matter.Current Behavior
Steps to Reproduce
Create test file 1:
Create test file 2:
When running both test files in this order (e.g. via IntelliJ or Gradle), both tests succeed.
When running file2 and then file1, then the test in file1 fails:
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Minimal reproducible code (the gist of this issue)
see above
The text was updated successfully, but these errors were encountered: