我正在尝试使用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,则通过测试,不明白为什么?
由于
答案 0 :(得分:1)
您的项目缺少SLF4j实现之一。如果您使用Maven,请确保它包含在您的CLASSPATH中,或在您的POM中定义。