Search code examples
javajmock

What is the alternative to @RunWith(JMock.class)?


We have moved to Java 1.7 and now Jmock.class is deprecated. Is there an alternative? Seems the website has been abandoned...


Solution

  • You probably want the JUnitRuleMockery rule.

    public class TestSomething {
        @Rule
        public final JUnitRuleMockery context = new JUnitRuleMockery();
    
        @Mock
        private MyInterface interface;
    
        @Test
        public void testTheThing() {
            context.checking(new Expectations{{
    
             }});
            // etc.
        }
    

    You'll need the jmock-junit4 dependency on your classpath...

            <dependency>
                <groupId>org.jmock</groupId>
                <artifactId>jmock-junit4</artifactId>
                <version>2.8.1</version>
                <scope>test</scope>
            </dependency>