asked on
junit errors
while executing junit getting below error
my service class and pojo and test class with main method as below(test class with main method works fine)
package com.je.service;
import java.util.UUID;
import com.je.Employee;
public class EmployeeService {
public Employee getEmployeeDetails(Employee emp) {
emp.setName(emp.getName().toUpperCase());
emp.setRandomId(UUID.randomUUID().toString());
return emp;
}
}
package com.je;
public class Employee {
private String randomId;
private String name;
public String getRandomId() {
return randomId;
}
public void setRandomId(String randomId) {
this.randomId = randomId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Employee [randomId=" + randomId + ", name=" + name + "]";
}
}
package com.je;
import com.je.service.EmployeeService;
public class Test {
public static void main(String[] args) {
EmployeeService empService=new EmployeeService();
Employee emp=new Employee();
emp.setName("class to test junit");
Employee updatedEmployee=empService.getEmployeeDetails(emp);
System.out.println(updatedEmployee);
}
}
ASKER
Below is my test class. I forgot to post below code earlier
package com.je.service;
import static org.junit.jupiter.api.Assertions.*;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import com.je.Employee;
class EmployeeServiceTest {
@Test
void getEmployeeServiceDetailsTest() {
EmployeeService empService=new EmployeeService();
Employee emp=new Employee();
emp.setName("class to test junit");
Employee updatedEmployee=empService.getEmployeeDetails(emp);
assertEquals(updatedEmployee.getName(), emp.getName());
fail("Not yet implemented");
}
}
Thank you for clarifying
The problem is that assertEquals(String, String) is not implemented by JUnit: Assertions (JUnit 5.0.1 API) and getName() returns String.
ASKER
please advise
ASKER
Hi.
It would be also helpful if you post EmployeeServiceTest.java, the most interesting is line 22. What kind of assertion is there?