Link to home
Create AccountLog in
Avatar of gp
gpFlag for United States of America

asked on

junit errors

while executing junit getting below error

User generated image


my service class and pojo and test class with main method as below(test class with main method works fine)User generated image


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);
   
}
}

Open in new window




Avatar of Arty K
Arty K
Flag of Kazakhstan image

Hi.
It would be also helpful if you post EmployeeServiceTest.java, the most interesting is line 22. What kind of assertion is there?

Avatar of gp

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.

Avatar of gp

ASKER

which one I supposed to use in this case

please advise
ASKER CERTIFIED SOLUTION
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of gp

ASKER

got it let me try today evening and confirm
Avatar of gp

ASKER

It is working fine now. Thank you

User generated image