@RunWith(JMock.class) 的替代方法是什么?

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

我们已移至 Java 1.7,现在 Jmock.class 已弃用。有其他选择吗?网站好像被废弃了...

您可能需要 JUnitRuleMockery 规则。

public class TestSomething {
    @Rule
    public final JUnitRuleMockery context = new JUnitRuleMockery();

    @Mock
    private MyInterface interface;

    @Test
    public void testTheThing() {
        context.checking(new Expectations{{

         }});
        // etc.
    }

您需要在类路径上依赖 jmock-junit4...

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