Eclipse throws java.lang.NullPointerException when running Spring JUnit
当我运行我的 junit 测试时,控制台打印此 Excpetion:
java.lang.NullPointerException
at org.eclipse.jdt.internal.junit4.runner.SubForestFilter.shouldRun(SubForestFilter.java:81)
at org.junit.internal.runners.JUnit4ClassRunner.filter(JUnit4ClassRunner.java:110)
at org.junit.runner.manipulation.Filter.apply(Filter.java:47)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:34)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
像这样的基本测试对象
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath*:config/spring/appcontext-*.xml",
"classpath*:config/sqlmap/*.xml"
})
@TransactionConfiguration(defaultRollback = false)
@Transactional
public abstract class AbstractTestObject {
static {
//DOMConfigurator.configure("target/classes/log/log4j.xml");
}
}
而JUnit方法就像这样:
public class StaffInfoServiceImplTest extends AbstractTestObject{
@Autowired
StaffInfoServiceImpl service;
@Test
public void insertTest() {
StaffInfo bo = new StaffInfo();
bo.setEmail("a@b.com");
bo.setEntId(1);
bo.setEntStaffNum("000XXXX");
bo.setName("julia");
bo.setPhone("00000000");
bo.setSerialNum("SD12233KSRONDU189342ND");
bo.setSuperior(2321);
bo.setDepartment("Sale");
bo.setSingleCredit(BigDecimal.valueOf(100));
bo.setMonthlyCredit(BigDecimal.valueOf(10000));
SLTContext c = new SLTContext();
c.setOperator("0000001");
service.insertStaffInfo(bo, c);
}
}
我的项目是Java EE项目,使用maven来管理lib,使用spring管理bean。
我的开发环境是:
Mac OS X Yosetime 10.10.4
Eclipse Java EE IDE for Web Developers(版本:Mars Release (4.5.0))
Maven 插件(从 Eclipse->安装新软件)
我想这是eclipse junit和project junit config之间的冲突,但我不确定。
如何解决问题,谢谢。