I am using spring boot and maven framework to set up microservice. Now i want to do some tests to make sure they are working properly. However, I am not sure how i should invoke them when i run the test. Or is my way of testing micro service correct? Thanks in advance
i have tried to invoke the micro services in the test java file but failed
this is the interface
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
...
@Modifying
@Query(value = "insert into Employee (id,fullname) values (:id,:fullname)",
nativeQuery = true)
void insertEmployee(@Param("id") int id,@Param("fullname") String fullname);
...
}
this is the class that handles mappings
public class EmployeeResource {
@Autowired
EmployeeRepository usersRepository;
@PostMapping(value="/add")
@Transactional
public void add(...){...}
}
I tried to invoke them by using this but failed because database is not updated
1
@Test
@Transactional
public void testInsert(){
EmployeeResource er = new EmployeeResource();
er.add(999,"test");
ArrayList<Employee> test = (ArrayList<Employee>)er.find(999);
}
2
@Test
@Transactional
public void testInsert(){
EmployeeRepository usersRepository;
usersRepository.insertEmployee(999,"test");
ArrayList<Employee> test =
(ArrayList<Employee>)usersRepository.findEmp(999);
}
Aucun commentaire:
Enregistrer un commentaire