相关疑难解决方法(0)

PowerMock:如何取消模拟方法?

我有一个静态方法,使用PowerMock进行模拟以抛出异常.(它删除文件.)不幸的是,在我的@After(每次测试后)方法中,我需要在没有模拟的情况下调用此方法.我该如何摆弄方法?

我没有看到相当于Mockito.reset().[参考:mockito:如何取消模拟方法?]

例:

@RunWith(PowerMockRunner.class)
@PrepareForTest(PathUtils.class)  // Important: This class has a static method we want to mock.
public class CleaningServiceImplTest2 extends TestBase {

    public static final File testDirPath = new File(CleaningServiceImplTest2.class.getSimpleName());

    @BeforeClass
    public static void beforeAllTests() throws PathException {
        recursiveDeleteDirectory(testDirPath);
    }

    @AfterClass
    public static void afterAllTests() throws PathException {
        recursiveDeleteDirectory(testDirPath);
    }

    private File randomParentDirPath;
    private CleaningServiceImpl classUnderTest;

    @Before
    public void beforeEachTest() {
        randomParentDirPath = new File(testDirPath, UUID.randomUUID().toString()).getAbsoluteFile();
        classUnderTest = new CleaningServiceImpl(randomParentDirPath);
    }

    @After
    public …
Run Code Online (Sandbox Code Playgroud)

java testing powermock

14
推荐指数
1
解决办法
8940
查看次数

标签 统计

java ×1

powermock ×1

testing ×1