Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
这是我在运行测试用例时收到的错误 .
这是文件 .
package com.shanu.shopbackend.test;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.shanu.shopbackend.dao.CategoryDAO;
import com.shanu.shopbackend.dto.Category;
public class CategoryTestCases {
private static AnnotationConfigApplicationContext context;
private static CategoryDAO categoryDAO;
private Category category;
@BeforeClass
public static void init(){
context = new AnnotationConfigApplicationContext();
context.scan("com.shanu.shopbackend");
context.refresh();
categoryDAO= (CategoryDAO)context.getBean("categoryDAO");
}
@Test
public void testAddCategory() {
category = new Category();
category.setName("Test Mobile");
category.setDescription("Mobile Descp");
category.setImageURL("CAT_2.png");
assertEquals("Succesfully Added a Category",true,categoryDAO.add(category));
}
}
对于某些测试用例,我发现环境变量设置为空 .
1 回答
该错误表明您的Java安装存在问题,或者至少Eclipse无法找到它 .
您可以尝试将其添加到
eclipse.ini
文件中 . 请务必更新指向实际Java安装的路径 .资料来源:https://wiki.eclipse.org/Eclipse.ini#-vm_value:_Windows_Example