[英]No runnable methods on JUnit test class (netbeans)
请帮帮我!
我已经创建了一个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.
}
}
您需要按如下所示在测试方法中添加注释:
@Test
public void testGetSalary(){
与Junit 3不同,JUnit 4依靠注释而不是方法名称来标识测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.