Questions tagged [easymock]

Easymock is a mocking framework for Java.

Easymock is an open source mocking framework for Java. It is used for creating mock objects and stubs for unit tests.

999 questions
32
votes
5 answers

EasyMock: test that method in mock isn't called

As per title, just wondering if there is a mechanism with easymock to test if a method wasn't called during it's lifetime.
Ian
  • 321
  • 1
  • 3
  • 3
30
votes
3 answers

What is the difference between PowerMock, EasyMock and Mockito frameworks?

I am very new to mocking framework, and my work needs mocking framework to finish unit testing. In the current code base i could see above 3 frameworks are being used in different places for unit testing. So, which one should i go for in the above 3…
keya
  • 2,068
  • 2
  • 18
  • 18
29
votes
2 answers

How to mock a static final variable using JUnit, EasyMock or PowerMock

I want to mock a static final variable as well as mock a i18n class using JUnit, EasyMock or PowerMock. How do I do that?
Gnik
  • 7,120
  • 20
  • 79
  • 129
27
votes
9 answers

PowerMock ECLEmma coverage issue

We are using EasyMock and PowerMock with JUnit. The coverage tool used is ECLEmma. With EasyMock, it shows the coverage properly in green (as covered). However, for the code that is unit tested with PowerMock, the coverage is shown in red…
venkatesh
  • 435
  • 1
  • 5
  • 9
26
votes
5 answers

DAO Unit testing

I have been looking at EasyMock and tutorials/examples around using it for Unit Testing DAO classes, for an "outside container" test. However, I think most of them talk about testing the Service Layer instead, mocking the DAO class. I am a bit…
Dchucks
  • 1,189
  • 5
  • 22
  • 48
24
votes
1 answer

Alternatives to @VisibleForTesting

I understand that @VisibleForTesting is not desirable because it changes the interface of a class just for testing purposes. Ideally we should test the interface that we actually use. But what would be a good alternative?
Thiago
  • 2,238
  • 4
  • 29
  • 42
24
votes
3 answers

EasyMock expectations with void methods

I'm using EasyMock to do some unit tests and I don't understand the usage of EasyMock.expectLastCall(). As you can see in my code below, I have an object with a method that returns void getting called in some other object's method. I would think…
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
23
votes
4 answers

EasyMock : java.lang.IllegalStateException: 1 matchers expected, 2 recorded

I am having a problem with EasyMock 2.5.2 and JUnit 4.8.2 (running through Eclipse). I have read all the similar posts here but have not found an answer. I have a class containing two tests which test the same method. I am using matchers. Each test…
Anne
  • 233
  • 1
  • 2
  • 4
23
votes
2 answers

Getting EasyMock mock objects to throw Exceptions

I'm in process of using EasyMock to write Unit tests for a number of collaborating classes. One of these classes (lets call it Foo) opens a network connection to a remote server and parses that servers' XML response into something the rest of the…
Jon
  • 3,510
  • 6
  • 27
  • 32
23
votes
6 answers

Test that void method didn't get called with EasyMock

Is this possible? I tried with EasyMock.expectLastCall().times(0); but EasyMock complains that times must be >=1
nkr1pt
  • 4,691
  • 5
  • 35
  • 55
23
votes
3 answers

EasyMock 3.0, mocking class throws java.lang.IllegalStateException: no last call on a mock available

Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available import org.easymock.*; import org.junit.*; public class MyTest { @Test public void testWithClass() { Thread…
Nathan Reese
  • 311
  • 1
  • 3
  • 6
22
votes
4 answers

Mockito preferrable over EasyMock?

Recently I made the switch to Mockito framework and am very happy with it (see also blog-post). The switch from EasyMock to Mockito was very straightforward and I managed to make the tests down compatible (i.e. test cases behave the same). Do you…
manuel aldana
  • 15,650
  • 9
  • 43
  • 50
22
votes
1 answer

Using easymock, repeated void method call

I am new to easymock. I am trying to mock a service where one of the methods is a void method that will get called an unknown (and large) number of times. How do I specify that any number of calls is allowed? I know how to do it for methods that…
Hendrik
  • 1,355
  • 3
  • 11
  • 30
21
votes
4 answers

Testing private method using power mock which return list of Integers

I have a private method which take a list of integer value returns me a list of integer value. How can i use power mock to test it. I am new to powermock.Can i do the test with easy mock..? how..
user882196
  • 1,691
  • 9
  • 24
  • 39
21
votes
1 answer

unit testing functions with Apache Camel Exchange as parameter

I am doing java camel development and I want to unit test(junit4) a bunch of functions with Exchange being passed in as parameter. For example : public finalObject getProperty(final Exchange exchange, final String property) throws Exception { …
RoundPi
  • 5,819
  • 7
  • 49
  • 75
1
2
3
66 67