Skip to content

Instantly share code, notes, and snippets.

@abyx
Created August 11, 2011 16:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abyx/1140074 to your computer and use it in GitHub Desktop.
Save abyx/1140074 to your computer and use it in GitHub Desktop.
Reusing context with JUnit Enclosed runner
@RunWith(Enclosed.class)
public class OuterClassTest {
@Mock protected Dependency dependency;
protected SUT subject;
@Before
public void setUp() {
subject = new SUT(dependency);
}
@RunWith(MockitoJUnitRunner.class)
public static class FirstScope extends OuterClassTest {
@Test
public void someTest() {
subject.doSomething();
verify(subject).didSomething();
}
}
@RunWith(MockitoJUnitRunner.class)
public static class SecondScope extends OuterClassTest {
@Test
public void differentTest() {
subject.doSomethingElse();
verify(subject).didSomething();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment