Antonio
Antonio

Reputation: 324

Using EasyMock with TestNG

I know there two ways to use the "Mock" and the "TestSubject" annotations with JUnit. The first one - is to specify the EasyMockLoader class object for the RunWith annotation for the class that contains fields marked by these annotations. The second one - is to mark the EasyMockRule field with the "Rule" annotation. How to use the "Mock" and the "TestSubject" annotations with TestNG ?

Upvotes: 2

Views: 635

Answers (2)

Henri
Henri

Reputation: 5721

TestNG is not directly supported. But you can inject mocks using the annotations quite easily by doing

EasyMockSupport.injectMocks(this);

(from your test class)

Upvotes: 5

juherr
juherr

Reputation: 5740

As I known, EasyMock doesn't support TestNG out of the box but PowerMock does. Maybe using PowerMock + EasyMock + TestNG will work like a charm.

Otherwise, about @Mock, you'll have to manage it by yourself (looking for fields, creating mock and injecting them) with a configuration method (a @BeforeX method) or an appropriate listener. Another solution could be to use the Guice integration and making mocks in a Guice module.

Same solution for @TestSubject: configuration methods or listeners.

Upvotes: 1

Related Questions