Reputation: 37
Help me please!
I have created an EmployeeTest
class to write to an Employee
class but this error occurs before I can finish it. I had written the similar project before this project, it ran without errors. This is a very simple class as you can see below.
This is the error message:
initialization ERROR : No runnable methods
-No runnable methods
-java.lang.Exception
-at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
This is EmployeeTest
class:
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);
}
}
This is unfinished Employee
class:
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.
}
}
Upvotes: 1
Views: 10826
Reputation: 12527
You need to add annotations to your test methods as follows:
@Test
public void testGetSalary(){
Unlike Junit 3, JUnit 4 relies on annotations, not method names to identify tests.
Upvotes: 7