gpt4 book ai didi

java - 使用mockito测试用例执行失败

转载 作者:行者123 更新时间:2023-12-01 12:45:56 25 4
gpt4 key购买 nike

我正在尝试使用 mokito 框架执行测试用例,但遇到了一些错误。下面是我的代码:

public interface SaleforceSearchLeadService {
public String buildSOSL(String email);
}
public class SalesforceLeadSearch1 implements SaleforceSearchLeadService{
public SalesforceLeadSearch1(){
}
private final static Logger LOGGER = LoggerFactory.getLogger(SalesforceLeadSearch1.class);
public String buildSOSL(String email)
{
StringBuilder query = new StringBuilder();
query.append("SELECT FirstName, LastName, Company, Status, Email, Age__c FROM LEAD ");
query.append("WHERE Email = '"+email+"'");
return query.toString();
}
}
public class SalesforceLeadSearch1Test {
@Mock
private SaleforceSearchLeadService service;
@Test
public void testBuildSOSL() {
SalesforceLeadSearch1 test=new SalesforceLeadSearch1();
StringBuilder query = new StringBuilder();
String email="vivek.k@abc.com";
query.append("SELECT FirstName, LastName, Company, Status, Email, Age__c FROM LEAD ");
query.append("WHERE Email = '"+email+"'");
// assertEquals("SELECT FirstName, LastName, Company, Status, Email, Age__c FROM LEAD WHERE Email = 'vivek.k@abc.com'",service.buildSOSL(email));
assertEquals("SELECT FirstName, LastName, Company, Status, Email, Age__c FROM LEAD WHERE Email = 'vivek.k@.com'",test.buildSOSL("vivek.k@abc.com"));

}
}

下面是堆栈跟踪:

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.ig.igwebcms.services.impl.SalesforceLeadSearch1.<clinit>(SalesforceLeadSearch1.java:40)
at com.ig.igwebcms.services.test.SalesforceLeadSearch1Test.testBuildSOSL(SalesforceLeadSearch1Test.java:39)

即使我尝试使用给我 NPE 的服务实例。

如果我从 SalesforceLeadSearch1 类中删除 Logger,它就会通过测试,不明白为什么?

谢谢

最佳答案

您的项目缺少 SLF4j 实现之一。如果您使用 Maven,请确保它包含在您的 CLASSPATH 中,或者在您的 POM 中定义。

关于java - 使用mockito测试用例执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24709404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com