Open Zwaartekracht opened 3 years ago
@Zwaartekracht Need some more context to be able to help
at com.example.wichtelquiz.framework.SpielerTest.jokerWeg(SpielerTest.kt:115) ...
Is this the same as?
var mock : Frage = mock()
What does Frage
look like? Did you maybe forget to make Frage
open or are you maybe using Mockito-Inline artifact or all-open plugin wrong?
Also at the end you write:
Version is 2.8.5
Mockito-kotlin latest version is 2.2.0
Hi sorry you are right:-) androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
in my gradle ;-) 2.8.5 was my gson.
The Frage class is completely open as running a single test works I told that but running them all together nnot :-)
@Zwaartekracht Any chance that you could post an example of your test-class with implementations of Spieler
and Frage
. It doesn't have to be the exact implementation from your project. Just implementations inside the test-class that makes it possible to reproduce.
I also noticed that you use:
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
Are you maybe using inline mocking inside an instrumentation test? Because that won't work.
Yes they are instrumentation tests as I need a context. You mean mocking an app context instead of instrumentation would work.
@Zwaartekracht Not sure why jokerWeg
pass when run as a single test and not when run all together. To me it sounds as if you have state leaking between your tests.
This is a longshot, but maybe try initializing your Spieler
-class without lateinit var
and remove the Before
and After
functions, you don't need them. This ensures that your subject under test (sut) is created from scratch between your tests:
class SpielerTest {
private val wichtel = Spieler("Wichtel")
@Before // Remove this function
fun vorJedemTest() {
wichtel = Spieler("Wichtel")
}
@After // Remove this function
fun nachJedemTest() {
}
...
Hi,
my tests look like
package com.example.wichtelquiz.framework
import com.example.wichtelquiz.edm.Frage import com.nhaarman.mockitokotlin2. import org.junit.After import org.junit.Assert. import org.junit.Before import org.junit.Test import org.mockito.Mock import org.mockito.internal.invocation.MockitoMethod import org.mockito.internal.verification.Times
class SpielerTest { lateinit var wichtel: Spieler
}
running jokerWeg alone is green but as soon as I run the complete classe jokerWeg gets red.
org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here: -> at com.nhaarman.mockitokotlin2.VerificationKt.verify(Verification.kt:42)
Example of correct verification: verify(mock).doSomething()
Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods. Those methods cannot be stubbed/verified. Mocking methods declared on non-public parent classes is not supported.
Process finished with exit code -1
Can you help what I am missing here? Version is 2.8.5
Cheers Silke