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
6
votes
1 answer

PowerMockRunner causes ExceptionInInitializerError when running trivial test

I cannot run a very simple test class using the Powermock test runnner. It causes an ExceptionInInitializerError. It looks to be a problem with the dependencies on the classpath, however, I have tried a few variants of the dependency versions, but…
amoe
  • 4,473
  • 4
  • 31
  • 51
6
votes
3 answers

EasyMock -- mock methods within tested class?

In my code I sometimes call public or private methods within the same class. These methods aren't a good candidate for being pulled out into their own class. Each of these methods that I call are tested in their own unit test. So, if I have a method…
Jeremy
  • 5,365
  • 14
  • 51
  • 80
6
votes
3 answers

Mocking a final method with PowerMock + EasyMock

I'm trying to mock a call to the final method ResourceBundle.getString(). With PowerMock 1.4.12 and EasyMock 3.1, the call is not being mocked; instead, the "real" method is called. My test…
Mike Woinoski
  • 3,123
  • 1
  • 16
  • 15
6
votes
3 answers

EasyMock expecting private method calls

Lets say I have a method that looks like this: public static String[] parseFoo(Foo anObject){ Foo anotherObject = parseFoo2(anObject); ... } private static Foo parseFoo2(Foo anObject){ ... } and both methods are in the same class. parseFoo2 is…
KWJ2104
  • 1,959
  • 6
  • 38
  • 53
6
votes
2 answers

Java unit test can't access ResourceBundle

I am creating a Java unit test to test some code I recently changed. However, the method I am testing instantiates a class which uses ResourceBundle … ResourceBundle.getBundle("businessVariables").getString("product.name")); The resource file lives…
Andy A
  • 4,191
  • 7
  • 38
  • 56
6
votes
1 answer

Does "EasyMock.expectLastCall();" do anything without a further call to resulting IExpectationSetters?

Consider this code snippet:- Whatever mock = EasyMock.createMock( Whatever.class ); mock.doSomething(); EasyMock.expectLastCall(); // <- Does this do anything? EasyMock.replay( whatever ); Does expectLastCall() here actually do anything? Adding…
WW.
  • 23,793
  • 13
  • 94
  • 121
5
votes
4 answers

EasyMock and Unitils equivalent to Mockito @ InjectMocks

Is there any techniques available in EasyMock or Unitils Mock (Not Unitils supported EasyMock) to inject the mocks directly into the Class Under Test? For eg. in Mockito it is possible to inject mocks directly into member variables of a…
Bala
  • 1,193
  • 2
  • 12
  • 34
5
votes
3 answers

PowerMock EasyMock Fundamentals

This one is probably a PowerMock/EasyMock 101 question which I cannot figure out why. I have a class C with methods public static boolean testInner(String s) { return false; } public static boolean testOuter() { String x = "someValue"; …
phewataal
  • 1,107
  • 4
  • 12
  • 23
5
votes
3 answers

EasyMock gentle introduction?

I am completely baffled while trying to use EasyMock. Does anybody know of a (very) gentle introduction to EasyMock? I already heavily use TDD, and I use mocking (which I guess is almost a prerequisite for doing TDD). I have just never used a…
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
5
votes
1 answer

Equivalent of LastCall.IgnoreArguments in EasyMock

I have used Rhino.Mocks extensively currently writing some tests in Java using EasyMocks. However I was unable to pull out a LastCall.IgnoreArguments() Rhino.Mocks equivalent in EasyMocks. How do I use Easy Mocks to return a value irrespective of…
abhilash
  • 5,605
  • 3
  • 36
  • 59
5
votes
1 answer

How do I mock a method inherited from an abstract class with EasyMock?

I'm struggling with EasyMock. I've written two small classes to illustrate my problem: public abstract class A { private AtomicReference id = new AtomicReference(null); public final int getId() { return id.get(); …
hvth
  • 147
  • 1
  • 11
5
votes
4 answers

How does "static reflection" work in java? (ex. in mockito or easymock)

I'm a .NET guy - and I mainly code in C#. Since C# 3.0, we can leverage lambda expressions and expression trees to use static reflection. For example, it is possible to implement GetMethodName in the following snippet to return the name of the…
Romain Verdier
  • 12,833
  • 7
  • 57
  • 77
5
votes
1 answer

mock final class: powermock + easymock + testng

I'm new to PowerMock and can't find an example that matches my situation. It's nothing complicated-- I am trying to use PowerMock+EasyMock to mock a final class in a TestNG test. Here's the final class: public final class MyFinalClass { private…
Atul
  • 51
  • 1
  • 2
5
votes
4 answers

Mocking EJB injection in tests

Whenever I want to test a class which uses resource injection I end up including a constructor that will only be used within the test: public class A { @EJB B b; // Used in tests to inject EJB mock protected A(B b) { this.b…
eliocs
  • 18,511
  • 7
  • 40
  • 52
5
votes
2 answers

How do I mock static function (Object function, not class function) in scala

Object A { def a = { something} } // I've import A, but still have error message: not found: type A val x = mock[A]
user398384
  • 1,124
  • 3
  • 14
  • 21