我有一个基于Spring的应用程序,正在进行单元测试。我使用TestNG进行单元测试。在我的测试中,我需要使用PowerMockito来模拟一些静态方法。我还需要使用一个测试Spring配置文件仅针对我的单元测试。
我无法将所有三个内容组合编写我的单元测试,即TestNg、PowerMock和Spring。我可以通过扩展AbstractTestNGSpringContextTests类将TestNG和Spring结合起来,但无法模拟静态方法,而是执行实际的静态方法。就像以下内容:
我可以通过扩展PowerMockTestCase类将TestNG与PowerMockito结合使用。但是,测试Spring配置文件无法解析。就像下面这样:
我无法将所有三个内容组合编写我的单元测试,即TestNg、PowerMock和Spring。我可以通过扩展AbstractTestNGSpringContextTests类将TestNG和Spring结合起来,但无法模拟静态方法,而是执行实际的静态方法。就像以下内容:
@PrepareForTest(MyUtils.class)
@ContextConfiguration(locations = { "classpath:config/test-context.xml"})
public class MyImplTest extends AbstractTestNGSpringContextTests{
.....
}
我可以通过扩展PowerMockTestCase类将TestNG与PowerMockito结合使用。但是,测试Spring配置文件无法解析。就像下面这样:
@PrepareForTest(MyUtils.class)
@ContextConfiguration(locations = { "classpath:config/test-context.xml"})
public class MyImplTest extends PowerMockTestCase{
.....
}
有没有办法让我编写结合TestNG、PowerMockito和Spring上下文的单元测试?