I'm currently trying to implement a Test where I create a User and then checking the Database if the new User is there. For that, I want to access my service class, but for some Reason the Service is always Null. I tried using Autowired, but that also didn't work.
My Testclass :
public class UserTest {
@Autowired
private UserdataService userdataService;
@ParameterizedTest
@MethodSource("Selenium.WebDriverFactory#getAll")
public void createUser(final WebDriver driver) throws InterruptedException{
List<UserdataDto> users = getAllUsers();
UserdataDto user = users.get(users.size() - 1);
assertEquals(user.getEmail(), "testUser@email.com");
}
@ResponseBody
public List<UserdataDto> getAllUsers() {
return userdataService.getAllUsers();
}
}
Error:
java.lang.NullPointerException: Cannot invoke "service.UserdataService.getAllUsers()" because "this.userdataService" is null
at Selenium.UserTest.getAllUsers(UserTest.java:78)
at Selenium.UserTest.createAndDeleteUser(UserTest.java:57)