<dependency> <groupId>org.testng</groupId> <artifactId>jmockit</artifactId> <version>1.49</version> <scope>test</scope> </dependency> import mockit.*; import org.testng.annotations.Test; public class ExampleTest { @Test public void testExample(@Mocked ExampleService exampleService) { new Expectations() {{ exampleService.doSomething(); result = "Mocked Result"; }}; Example example = new Example(exampleService); String result = example.doSomething(); new Verifications() {{ exampleService.doSomething(); times = 1; }}; Assert.assertEquals(result, "Mocked Result"); } } new RecordExpectations() {{ exampleService.doSomething(); result = "Expected Result"; }}; new Replay() {{ String result = exampleService.doSomething(); Assert.assertEquals(result, "Expected Result"); }}; @Capturing(Example.class) Example capturedExample; @Mocked(invocations = 1) ExampleService mockedService; public class ExampleMockUp extends MockUp<Example> { @Mock public void $init(ExampleService exampleService) { } @Mock public String doSomething() { } } ExampleMockUp mockUp = new ExampleMockUp(); mockUp.setUp();


上一篇:
下一篇:
切换中文