0

In the Context of JUnit, what is the difference between @inject and @mock, and in which conditions both can be used?

thanks, Rohit

user1254554
  • 203
  • 1
  • 4
  • 14
  • If you want to use both annotations in your tests, you might want to have a look at https://github.com/ArcBees/Jukito. – spg Feb 04 '15 at 22:12

1 Answers1

2
@Inject

... is an annotation which is defined in Guice and is quite simliar to Spring @Autowire. You can use these Annotations to inject a Object which you whant to use in your tests (i.e. persistence context to work with jpa)

@Mock

... is an annotation to (more or less) inject mock objects into your test class. In the method annoteted with @Before you can initialize the @Mock annoteted attributes via MockitoAnnotations.initMocks(this). Another way you can go is to annotate the testclass with @RunWith(MockitoJUnitRunner.class).

I hope this will help for the first steps ;-)

ChangeRequest
  • 532
  • 4
  • 12