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:

  1. I’m writing a new AnnotationSpec test, utilizing @Mock and @InjectMock to provide dependencies I need.
  2. But I forget to @Mock-inject something and Mockito cannot construct the @InjectMock-annotated object and throws InjectMocksException from the initMocks().
  3. 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

Most upvoted comments

4.0.7 has been released.

On Tue, 16 Jun 2020 at 22:53, Stephen Samuel (Sam) sam@sksamuel.com wrote:

We can do 4.0.7 yes.

Also please let us know what issues you’re having with the plugin and 4.1.

On Tue, 16 Jun 2020, 22:37 Andrey Bolduzev, notifications@github.com wrote:

Hi @andrey-bolduzev https://github.com/andrey-bolduzev That fix was released 4.1.0-RC1 few days back. You can use latest 4.1.0-RC2.

Yep, I know it’s fixed in the 4.1 branch but the adoption of the kotest intellij plugin is not going too well in my team, I am having a hard time getting it to work in a complex project myself. I was going to raise an issue in the plugin repo once I figure out what exactly is happening. But in the meantime, I was hoping another small 4.0 release could be made since the work to cherry-pick the change was done already anyway if I’m not mistaken.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kotest/kotest/issues/1426#issuecomment-645127409, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGWPFUF6TEHBRRYFALDRXA26FANCNFSM4MVVR7SA .

@andrey-bolduzev The bug is now fixed in master.