我收到PowerMock错误,但我没有使用PowerMocking.我正在使用正常的嘲弄.这是我要测试的课程:
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class IlinqBeanDataBuilder {
@Autowired
private Settings settings;
private static final String SERVICE_CODE_FOR_FACILITY_COUNTRY = "SERVICE_CODE_FOR_FACILITY_COUNTRY";
private static final String SERVICE_CODE_A_CONSTANT = "A";
private static final String HARD_DOWN = "HARD DOWN";
private static final String QUICK_QUESTION = "QUICK QUESTION";
private static final String PARTIAL_DOWN = "PARTIAL DOWN";
private static final String COMPLETELY_DOWN = "Completely Down";
private static final String UP = "Up";
private static final String PARTIALLY_DOWN = "Partially Down";
public …Run Code Online (Sandbox Code Playgroud) 我正在编写 Junits 来测试我的日志。我正在使用 LogCaptor。我已附上我的实际方法和测试用例以及 pom.xml。
这是我定义日志的方法。
@Override
public ApplicationResponse createApplication (final String serviceId, final String appId) throws KMSException {
log.debug("Entering createApplication");
try {
final Application application =
applicationOperations.createApplication(appId, serviceId);
return applicationResponse(application);
}
catch (KMSCommonException exception) {
throw new KMSInternalServerErrorException("Not able to create application", exception);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我test method要测试的记录器:
@Test
public void testCreateApplicationLogger () throws KMSException {
String expectedInfoMessage = "Entering createApplication";
LogCaptor logCaptor = LogCaptor.forClass(Test.class);
adminAPIApplicationOpService.createApplication(TEST_SERVICE, TEST_APP + 1);
assertTrue( logCaptor.getInfoLogs().contains(expectedInfoMessage));
}
Run Code Online (Sandbox Code Playgroud)