Quantcast
Channel: JetBrains Developer Community : Thread List - IntelliJ IDEA Users
Viewing all articles
Browse latest Browse all 5661

Auto-creation of mock variables when writing tests (or something similar)

$
0
0

I wonder what do people do in cases like:

I'm writing a test for a service class that depends on a lot of other classes, so I need to build it by passing various mocks to the constructor:

 

SomeClassUnderTest classUnderTest = new SomeClassUnderTest(dependency1, dependency2, dependency3, ...);

 

the question is, what is the best way to create everything quickly?

 

E.g.: I start by typing:

 

new SomeClassUnderTest(

 

at this point, I'd like to have a quick way to create mocks for all of the parameters, and use them, that is, for each param introduce a mock field in the test such as

 

@Mock DependencyType1 dependency1; // we use mockito for our mocks, but EasyMock is similar

 

and use that in the new clause:

 

new SomeClassUnderTest(dependency1,

 

then go on (or even do all of them in one go).

 

Do you guys have a quick solution for this workflow?


Viewing all articles
Browse latest Browse all 5661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>