请帮帮我!
我创建了一个EmployeeTest
类来写入Employee
类,但是在我完成它之前会发生此错误。我在这个项目之前编写了类似的项目,它运行没有错误。这是一个非常简单的类,如下所示。
这是错误消息:
initialization ERROR : No runnable methods
-No runnable methods
-java.lang.Exception
-at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
这是EmployeeTest
类:
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class EmployeeTest {
Employee employee;
public EmployeeTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
employee = new Employee("Austin", "Powers", 70000.00);
}
public void testGetName(){
String expected = "Austin Powers";
String actual = employee.getName();
assertEquals(expected, actual);
}
public void testGetSalary(){
double expected = 70000.00;
double actual = employee.getSalary();
double marginOfError = 0.0001;
assertEquals(expected, actual, marginOfError);
}
public void testChangeSalary(){
double percentIncrease = 5.00;
employee.changeSalary(percentIncrease);
double expected = 73500.00;
double actual = employee.getSalary();
double marginOfError = 0.0001;
assertEquals(expected, actual, marginOfError);
}
}
这是未完成的Employee
课程:
class Employee {
private String firstName;
private String lastName;
private double salary;
public Employee(String austin, String powers, double d) {
firstName = austin;
lastName = powers;
}
String getName() {
return firstName +" "+lastName;
}
double getSalary() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
void changeSalary(double percentIncrease) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
答案 0 :(得分:6)
您需要为测试方法添加注释,如下所示:
@Test
public void testGetSalary(){
与Junit 3不同,JUnit 4依赖于注释,而不是方法名来识别测试。