问题描述
jar包也更换过了..就是没果,,求解...Class not found test.UserTestjava.lang.ClassNotFoundException: test.UserTestat java.net.URLClassLoader$1.run(URLClassLoader.java:200)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:188)at java.lang.ClassLoader.loadClass(ClassLoader.java:307)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)at java.lang.ClassLoader.loadClass(ClassLoader.java:252)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 问题补充:求解: 我感觉自己的写的没什么问题了,这是源代码:package test;import java.util.Date;import java.util.HashSet;import java.util.List;import java.util.Set;import junit.framework.TestCase;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.pms.dao.IUserDao;import com.pms.model.PageModel;import com.pms.model.Role;import com.pms.model.User;public class UserTest extends TestCase {private IUserDao userDao = null;protected void setUp() throws Exception {ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"spring_common.xml","spring_beans.xml"});userDao = (IUserDao) ctx.getBean("userDao");}protected void tearDown() throws Exception {super.tearDown();}public void testAdd() {User u = new User();u.setUserName("asdfasdf");u.setPassword("msaden1");u.setRegistedTime(new Date());u.setLoginName("msaden1");u.setEmail("adfasdff@qq.com");u.setDescription("asddfghhouhy7it哦iysadf fasdf");u.setStatus(1);Set userSet = new HashSet();userSet.add(u);Role role = new Role();role.setName("xx");role.setCreationTime(new Date());role.setStatus(1);role.setUserSet(userSet);Role role1 = new Role();role1.setName("yy");role1.setCreationTime(new Date());role1.setStatus(1);role1.setUserSet(userSet);Set roleSet = new HashSet();roleSet.add(role);roleSet.add(role1);u.setRoleSet(roleSet);userDao.add(u);}public void testGetList() {PageModel pm = userDao.findList(1, 1);System.out.println(pm.getTotalPages() + pm.getTotalRows());System.out.println(pm.getRecords().size());}public void testGetById() {User user = userDao.findById("4028809b2c4e08d4012c4e08de5b0001");System.out.println(user.getUserName());}public void testUpdate() {User user = userDao.findById("4028809b2c4e08d4012c4e08de5b0001");user.setUserName("------------------");userDao.update(user);}public void testGetAll(){List list = userDao.findAll();System.out.println(list.size());}public void testUserLogin(){User user = userDao.login("asdfasd", "asdfasdf");this.assertNotNull(user);System.out.println(user.getUserName());}}
解决方案
java.lang.ClassNotFoundException: test.UserTest 为什么找不到你自己写的单元测试类?没放进去?你用什么方式运行单元测试的?改用其他方式也是这样吗?我遇见过这样的情况,发现时Eclipse被编译,建议你重新clean一次Eclipse工程, 重新Build一次晕死,测试方法应该这样写 test+方法名 例如 testadduser(){}
解决方案二:
我遇见过这样的情况,发现时Eclipse被编译,建议你重新clean一次Eclipse工程,重新Build一次
解决方案三:
你用什么方式运行单元测试的?改用其他方式也是这样吗?
解决方案四:
引用java.lang.ClassNotFoundException: test.UserTest 为什么找不到你自己写的单元测试类?没放进去?