java中的接口是类吗
339
2023-04-26
本文目录一览:
public class HelloWorld {
private static HelloWorld instance = new HelloWorld();
private HelloWorld() {}
public static HelloWorld getInstance() {return instance;}
public void say() {
System.out.println("Hello World!");
}
}
public class HelloWorld {
private static HelloWorld instance = new HelloWorld();
private HelloWorld() {}
public static HelloWorld getInstance() {return instance;}
public void say() {
System.out.println("Hello World!");
}
}
测试代码java mock 工具:
public class HelloWorldAppTest {
private HelloWorldApp helloWorldApp;
@Before
public void setUp() throws Exception {
helloWorldApp = new HelloWorldApp();
}
@Test
public void sayHelloWorld() throws Exception {
HelloWorld instanceMock = PowerMockito.mock(HelloWorld.class);
Whitebox.setInternalState(HelloWorld.class, "instance", instanceMock);
Mockito.doNothing().when(instanceMock).say();
helloWorldApp.sayHelloWorld();
Mockito.verify(instanceMock).say();
}
}
package cn.outofmemory.junit.jmockit;关于java mock 工具和javaagent mock的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。 java mock 工具的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于javaagent mock、java mock 工具的信息别忘了在本站进行查找喔。
import mockit.NonStrictExpectations;
import mockit.Injectable;
import mockit.MockUp;
import mockit.Mocked;
import mockit.Mockit;
import mockit.NonStrict;
import mockit.Tested;
public class MockTargetTest {
@BeforeClass
static public void beforeClass() {
Mockit.setUpMocks();
}
@Mocked
private MockTarget mt;
@Test
public void testPrivateMethodMock() {
new NonStrictExpectations(mt) {
{
// 对私有方法进行mock
this.invoke(mt, "privateMethod", anyString);
result = "Hello Object";
}
};
Object actual = mt.publicMethod();
assertEquals(actual,"Hello Object");
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~