kotest: AnnotationSpec: Exception in project-level `TestListener`'s `beforeSpec` causes all test cases to be silently not run
I have a project that uses Mockito for mocking. The project config looks something like this:
object KotestConfig : AbstractProjectConfig() {
override val isolationMode: IsolationMode? = InstancePerLeaf
override fun listeners(): List<TestListener> = listOf(MockitoInjectListener)
}
private object MockitoInjectListener : TestListener {
override suspend fun beforeSpec(spec: Spec) {
MockitoAnnotations.initMocks(spec)
}
}
The situation is as follows:
- I’m writing a new
AnnotationSpec
test, utilizing@Mock
and@InjectMock
to provide dependencies I need. - But I forget to
@Mock
-inject something and Mockito cannot construct the@InjectMock
-annotated object and throwsInjectMocksException
from theinitMocks()
. - From what I can see this makes the chain in
InstancePerLeafSpecRunner#executeInCleanSpec
fall through without executing the test cases but also without reporting its failure to do so. So when running all tests in the project, the developer assumes that everything is passing.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (15 by maintainers)
Commits related to this issue
- #1426 Fixes error in beforeSpec for InstancePerLeaf issolation mode not getting reported (#1439) * #1426 Adds a failing test to replicate the issue * #1426 Updates InstancePerLeafSpecRunner to Rep... — committed to kotest/kotest by ashishkujoy 4 years ago
- * #1426 Adds a failing test to replicate the issue * #1426 Updates InstancePerLeafSpecRunner to Report error in beforeSpec * #1426 Correct spec class name * #1426 Simplified fix by using getOrThrow... — committed to kotest/kotest by ashishkujoy 4 years ago
4.0.7 has been released.
On Tue, 16 Jun 2020 at 22:53, Stephen Samuel (Sam) sam@sksamuel.com wrote:
@andrey-bolduzev The bug is now fixed in master.