The class that I want to test is called UserService
with sendEmail
method, which sends an email to user.
To accomplish this task it depends on EmailService
. Now when writing a testcase to test this - should I create UserService userService = new UserService()
and mock Email service OR create context file define UserService
bean there and @Autowired UserService
in my test class and mock EmailService
?
What is the difference between both approaches and when should i use one over the other? Which of these is a real object?