我正在尝试使用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中定义。