java无法使用TestNG和JMockit注入@Test注释的方法
基本上,我想检查test()函数是否调用静态方法JOptionPane.showInputDialog("Enter a string.")
。这就是我迄今为止所取得的成就
使用的库:
- TestNG 7.4.0
- JMockit 1.49
当前测试代码:
package com.example;
import javax.swing.*;
import org.testng.annotations.Test;
import mockit.Mocked;
import mockit.Verifications;
public class Activity1Test {
@Test
public void shouldShowInputDialogOnUpdateTextButtonClick(@Mocked JOptionPane jOptionPane) {
Activity1 activity1 = new Activity1();
activity1.test();
new Verifications() {{ JOptionPane.showInputDialog("Enter a string."); }};
}
}
test()函数:
public void test() {
JOptionPane.showInputDialog("Enter a string.");
}
不幸的是,它给了我这个错误:
-------------------------------------------------------------------------------
Test set: TestSuite
-------------------------------------------------------------------------------
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.781 s <<< FAILURE! - in TestSuite
com.example.Activity1Test.shouldShowInputDialogOnUpdateTextButtonClick Time elapsed: 0.434 s <<< FAILURE!
org.testng.TestNGException:
Cannot inject @Test annotated Method [shouldShowInputDialogOnUpdateTextButtonClick] with [class javax.swing.JOptionPane].
For more information on native dependency injection please refer to https://testng.org/doc/documentation-main.html#native-dependency-injection
共 (0) 个答案