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
0
votes
2 answers

Using EasyMock to test a method that constructs another object

I have a method like this: public void MyMethod(int p1, int p2) { //some logic here MyObject mo = new MyObject(var1,var2); int returnedId = mo.doOperation(something); //Do something with the returnedId; } I want to test this method but I…
Jeremy
  • 5,365
  • 14
  • 51
  • 80
0
votes
1 answer

EasyMock: can andReturn give a runtime error?

I'm using EasyMock to mock a class called "Tuple". The Tuple.getString(int i) method is supposed to return the String at position i in the tuple. If that field is not a String, it will give a runtime error. In order for andReturn to work, I will…
Dao Lam
  • 2,837
  • 11
  • 38
  • 44
0
votes
1 answer

Android Easy Mock test Error

I am writing a test using Easy Mock and I get this error. I have added all the required jar files Objenesis and Cglib. Can anyone tell me why I am getting this error? java.lang.NoClassDefFoundError: org.easymock.EasyMock at…
quad
  • 872
  • 3
  • 17
  • 37
0
votes
1 answer

How to verify a specific expected method in easymock

How can I use Easymock.verify(mockedObject); to check only a specific expected method call on that mocked object instead of checking all the expected methods. In another words how can I verify the call of specific method rather than all of…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
1 answer

Easymock multiple method calls inside the test method

So I am using easymock to write unit test fpr a method inside my class. I have mocked an object inside this method and it works fine. The problem is inside this test method I have several calls to other methods inside the same class. For…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
3 answers

Can I check the return value of a db query with mocking?

So for my unit testing I am using easymock. I have a findProject method which queries the db and returns a list of the projects. I have mocked the object which returns the entityManger(I am using JPA and Hibernate). So it is something like :…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
1 answer

Unit testing a method with easymock

So I have the bellow method which I want to perform a unit test on. public List getProjects(Task task) { Criteria criteria = this.myRepository.getCriteria(Project.class); criteria.add(Comparison.eq("order",…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
3 answers

Unit testing by mocking the data layer or using embedded database

For unit testing is it better to mock the data layer or use an embedded database like derby? I know that it also depends on the purpose of the testing. But if I go with derby I don't have to mock all the objects and I assume that would be easier. On…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
1 answer

Persisting a mocked object with junit and easymock

So I have used easymock for mocking my data layer objects while unit testing. I am using JPA for persistency. E.g. Project project = EasyMock.cre..(Project.class); etc. Now the method which I want to test gets this project does some stuff and then…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
2 answers

EasyMock when we have a call to db on the test class

I am testing a class let say MyClass with JUnit. I am using easymock to isolate the need for db. It works fine. So if there is a call to a model object I just mock that object. E.g. if I have public void method(Project project) { project.getName();…
Sara
  • 2,417
  • 7
  • 35
  • 52
0
votes
1 answer

DRYing Up EasyMock Tests

It seems like EasyMock tests tend to follow the following pattern: @Test public void testCreateHamburger() { // set up the expectation EasyMock.expect(mockFoodFactory.createHamburger("Beef", "Swiss", "Tomato", "Green Peppers", "Ketchup")) …
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149
0
votes
1 answer

EasyMock PowerMock IllegalStateException with Ant and not IDEs

I am using Powermock 1.4.9 with Easymock extension. Following is the method that i want to test Public class SomeClass { public String methodToTest(String id) throws Exception { try { ClassA ojbectA =…
maverick
  • 549
  • 2
  • 10
  • 18
0
votes
2 answers

Autowiring beans implementing same interface - how to autowire a particular dependency bean in a JUnit Test?

I have a Spring 3.1/Java/Tomcat application. I have a service class that is as follows: public class SomeServiceImpl implements SomeService { @Autowired public AnotherService anotherService; // other code... This uses another service class…
Nilesh
  • 4,137
  • 6
  • 39
  • 53
0
votes
1 answer

EasyMock Expectation with a void method and an object array as argument?

When using EasyMock to set expectations for a void method, is it possible to specify an Object array as one of the arguments for the method? For example, if we have something like this: Errors mockErrors =…
Ashkan Aryan
  • 3,504
  • 4
  • 30
  • 44
0
votes
5 answers

EasyMock and File in Java

I'm programming application and i need to Mock File to test it. My code below: @Test public void testPostMail() throws Exception { Emailer instance = new Emailer(); instance.setRecipientsFromFile(new File("list.txt")); } The problem is, I…
user1227115
  • 843
  • 1
  • 8
  • 11