【发布时间】:2010-11-06 09:09:56
【问题描述】:
当试图从 Eclipse 中启动我的 JUnit-Test 时,我得到一个“ClassNotFoundException”。从控制台运行“mvn test”时 - 一切正常。此外,Eclipse 中没有报告任何问题。
我的项目结构如下:
- 父项目(pom-packaging)
- Web 项目(war-packaging - 我的 JUnit-test 在这里)
- 弹性项目
- 配置项目
edit:怎么找不到类?这是一个没有特殊库的简单 HelloWorld-Application。
这是我的 JUnit 的运行配置: alt text http://www.walkner.biz/_temp/runconfig.png
Testclass(但正如我所说;它也不适用于简单的 HelloWorld...):
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import biz.prognoserechnung.domain.User;
import biz.prognoserechnung.domain.UserRepository;
import biz.prognoserechnung.domain.hibernate.UserHibernateDao;
public class UserDaoTest {
/**
* the applicationcontext.
*/
private ApplicationContext ctx = null;
/**
* the user itself.
*/
private User record = null;
/**
* Interface for the user.
*/
private UserRepository dao = null;
@Before
public void setUp() throws Exception {
String[] paths = { "WEB-INF/applicationContext.xml" };
ctx = new ClassPathXmlApplicationContext(paths);
dao = (UserHibernateDao) ctx.getBean("userRepository");
}
@After
public void tearDown() throws Exception {
dao = null;
}
@Test
public final void testIsUser() throws Exception {
Assert.assertTrue(dao.isUser("John", "Doe"));
}
@Test
public final void testIsNoUser() throws Exception {
Assert.assertFalse(dao.isUser("not", "existing"));
Assert.assertFalse(dao.isUser(null, null));
Assert.assertFalse(dao.isUser("", ""));
}
}
【问题讨论】:
-
我在尝试运行一个不包含 JUnit 的简单 HelloWorld 类时遇到同样的错误......更准确地说:java.lang.NoClassDefFoundError: HelloWorld Caused by: java.lang.ClassNotFoundException: HelloWorld跨度>
-
ClassNotFoundException 在尝试反映类时抛出。当您尝试在普通方法调用中使用该类时,将引发 NoClassDefFoundError。
-
你能展示你的测试类的代码吗?
-
你是否开启或关闭了自动构建?
-
自动构建已开启
标签: java eclipse exception maven-2