- Nested classes can specify a new runner which overrides the parent runner.
- The
@ExtendWithspecifies the strictness as well and this strictness will be used for all tests. E.g.@ExtendWith(MockitoExtension.Silent.class)or@ExtendWith(MockitoExtension.Strict.class).@ExtendWith(MockitoExtension.class)is equivalent to the strict variant.- The user can opt-in to a different strictness per
method.The algorithm to retrieve the strictness is then:
As every runner already defines it strictness level, we don't need to fallback to the
- If Method has annotation, use that strictness
- Else use strictness specified by runner
DEFAULT_STRICTNESS.
@ExtendWith(MockitoExtension.Strict.class)
class Test {
@Mock Foo foo;
@Test //strict-stubbing inherited from Test
void test1(){
foo.bar();
}
@ExtendWith(MockitoExtension.Silent.class)
class NestedTest{
@Test //silent inherited from NestedClass
void test2(){
foo.bar();
}
@Test
@Strictness(WARN) //warn defined on method level
void test2(){
foo.bar();
}
}
}
@WithMockito to init mocks, spy's and so on like Junit4 @RunWith(MockitoJunitRunner)
@Strictness( ..) to set /override the strictness for the test-root-class, nested-test-classes and test-methods.
@WithMockito //init mocks, spys and captors, strictness is per default WARN
@Strictness(STRICT_STUBS) //optional annotation to defined strictness
class Test {
@Mock Foo foo;
@Test //strict-stubbing inherited from Test
void test1(){
foo.bar();
}
@Strictness(SILENT) //override the stricness from Test
class NestedTest{
@Test //silent inherited from NestedClass
void test2(){
foo.bar();
}
@Test
@Strictness(WARN) //warn defined on method level
void test2(){
foo.bar();
}
}
}
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/5d8a5401-692e-41c4-866e-7e53243253d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@WithMockito which implies a default stricness. Setting the stricness-level at the extension annotation level like @WithMockito(strictness=STRICT_STUBS)is suboptimal cause it would introduce a second concept to define the strictness parallel to @Strictness. --
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/6d81ba34-ea0e-4b75-b20b-e2ca4223011b%40googlegroups.com.
`@ExtendWith(MockitoJUnitRunner.class)` does exactly this right? It has a default strictness, without specifying default strictness.
I find `WithMockito` ambigous and non-JUnit5-like.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/7b568de6-956e-4d4e-8696-206a2c38775d%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/CALS12-Pf4X-V%3DL%3D-GQ_Cn8Lwg%3DH0fCAFszQ5eY9oTd-6i50QLw%40mail.gmail.com.
Oh just to make it complete: it should have been `@ExtendWith(MockitoJUnitExtension.class)`, so not with the runner. But that is a minor detail.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/7b568de6-956e-4d4e-8696-206a2c38775d%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/CALS12-Pf4X-V%3DL%3D-GQ_Cn8Lwg%3DH0fCAFszQ5eY9oTd-6i50QLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/VI1P194MB0077084B878A0EA7919DA6EFF6260%40VI1P194MB0077.EURP194.PROD.OUTLOOK.COM.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/7b568de6-956e-4d4e-8696-206a2c38775d%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/CALS12-Pf4X-V%3DL%3D-GQ_Cn8Lwg%3DH0fCAFszQ5eY9oTd-6i50QLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/VI1P194MB0077084B878A0EA7919DA6EFF6260%40VI1P194MB0077.EURP194.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/CAAYcR_J%3DYYniUDrrNqdXsx9qdEH5DZo6yG%3DFcfNqfhDf7XVpwQ%40mail.gmail.com.
Hey guys!FYI: I replied to issue 792 (https://github.com/mockito/mockito/issues/792#issuecomment-347048356), where we're considering making strictness configurable per mock / per stubbing. It is related to this discussion because having strictness per mock/stubbing reduces the value of the proposal 2.
@Mock
@Strictness(LENIENT)
Foo mock;
It fits to the same concept at method and class level declaration@Extends(MockitoJunitExtension.class)
@Strictness(STRICT_STUBS)
class Test {@Strictness(LENIENT)@Mock Foo foo;
@Strictness(SILENT)class NestedTest{@Test
@Strictness(WARN)}void test(){
foo.bar();
}
}
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/7a1c07a3-1bde-41ee-87ef-b5f0a273b09b%40googlegroups.com.