在将JDK 1.8升级到17后,一些Junit在创建构建时出现错误,但在独立运行该Junit时,其工作正常。
public class MyClassTest{
@InjectMocks
MyClass myClass;
@Mock
AlertRuleMappingUtility alertRuleMappingUtility;
AutoCloseable closeable;
@Before
public void setUp() {
closeable = MockitoAnnotations.openMocks(this);
}
@AfterEach
public void close() throws Exception {
closeable.close();
}
@Test
public void getDescriptionTextTest0() throws Throwable {
Map<String, String> map = new HashMap<>();
map.put("alert.secured_borrowings", "xyz");
myClass.setAlertType("secured_borroWings");
doReturn(map).when(alertRuleMappingUtility).fetchAlertTypeAndLongDescMapping(any());
String result = myClass.getDescriptionText();
assertNotNull(result);
}
}
我得到的错误是ERROR] MyclassTest.setUp:31 InvalidUseOfMatchers Misplaced or mis... [INFO] [ERROR] Tests run: 750, Failures: 0, Errors: 1, Skipped: 0
1条答案
按热度按时间w8rqjzmb1#
正如我所看到的,你混合了junt4和junit5
@Before
已退出4@AfterEach
是junit5您应该将
@Before
更改为@BeforeEach