I have written quite a few Mock objects using EasyMock. However, often i find writing partial mocks time consuming, and it does not feel 'right'.
I'd say its a design fault as my class I try to mock has multiple concerns into one, therefore I should create seperate classes in order to seperate concerns.
What do you think? Is partially ...
I have the following code
Record rd = registerNewRecord();
<do some processing>
rd.setFinished(true);
updateRecord(rd);
The registerNewRecord method calls the RecordDao insert method, and updateRecord calls the update method on the same DAO.
I have the following easymock code:
Capture<Record> insertRc = new Capture<Record>();
Record...
So, I need to test the Service Layer for an application (I need to test some methods - this is my first contact with the testing section)
public void testGetAllOrderedDescByRating() {
FAQ faq1 = initFAQ(new FAQ(), 5, 1L);
FAQ faq2 = initFAQ(new FAQ(), 3, 2L);
FAQ faq3 = initFAQ(new FAQ(), 11, 3L);
EasyMock.expect(faqDa...
As per title, just wondering if there is a mechanism with easymock to test if a method wasn't called during it's lifetime.
...
I'm using EasyMock to create mock objects for JUnit testing in Java. I create a mock object and pass it to another thread where it expects methods to be called. In the other thread, the calls are enclosed in a try/catch(Throwable) block, so when an unexpected call occurs on the mock and it thus throws AssertionError, that error is caught...
Hi,
I'm trying to setup a test in JUnit w/ EasyMock and I'm running into a small issue that I can't seem to wrap my head around. I was hoping someone here could help.
Here is a simplified version of the method I'm trying to test:
public void myMethod() {
//Some code executing here
Obj myObj = this.service.getObj(param);
i...
Using the latest version of EasyMock, I have a method that I need to stub out. The method takes an object parameter and returns void.
The stubbed method is being called by the method I'm testing. No surprises there. My difficulty is that the object that is supplied as an argument to the mocked method is being created by the method I'...
Hi, I'm mocking a method with easymock that has a date in its body, something like this:
public void testedMethod() {
...
if (doSomething(new Date())) {
...
}
And my test looks like this:
public void testThatMethod() {
...
expect(testedClass.testedMethod(new Date())).andReturn(false);
...
}
But when I run th...
Can anyone make any suggestions about how best to use EasyMock to expect a call to Runtime.getRuntime().exec(xxx)?
I could move the call into a method in another class that implements an interface, but would rather not in an ideal world.
interface RuntimeWrapper {
ProcessWrapper execute(String command) throws IOException;
}
interf...
So I've been using EasyMock's class extension for a while now. All of a sudden I'm getting this exception, but only when I run the entire test suite:
java.lang.IllegalStateException: 0 matchers expected, 1 recorded.
at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:42)
at org.easymock.internal.Exp...
I've got this in mycode:
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.reset;
import static org.easymock.classextension.EasyMock.verify;
...
mockMember = createMock(Member.class);
mockMember.incrPlayInPlay(20...
See code just bellow
Our generic interface
public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> {
void add(INSTANCE_CLASS instance);
INSTANCE_CLASS getById(INSTANCE_ID_CLASS id);
}
And a single class
public class Order {
private Integer id;
private Integer orderNumber;
// getter's and setter's
...
I'm little confused with Cactus and mock objects (jMock, Easy mock).
Could anyone please answer the following questions?
When to use Cactus for testing?
When not to use Cactus for testing?
When to use mock objects for testing?
When not to use mock objects for testing?
...
Hi, I have a method
public Object doSomething(Object o); which I want to mock. It shall just return its parameter. I tried:
Capture<Object> copyCaptcher = new Capture<Object>();
expect(mock.doSomething(capture(copyCaptcher))).andReturn(copyCatcher.getValue()); wihtout success, I get just an AssertionError "Nothing captured, yet". Any i...
Hello,
I have recently been introduced to EasyMock and have been asked to develop some unit tests for a FileMonitor class using it. The FileMonitor class is based on a timed event that wakes up and checks for file modification(s) in a defined list of files and directories. I get how to do this using the actual file system, write a tes...
Still Now I am using JUnit, I came across EasyMock, I am understanding both are for the same purpose.
Is my understanding correct?
What are the advantages does EasyMock has over the Junit?
Which one is easier to configure?
Does EasyMock has any limitations?
Please help me to learn
...
Hi,
We use hand written stubs in our unit tests and I'm exploring the need for a Mock framework like EasyMock or Mockito in our project.
I do not find a compelling reason for switching to Mocking frameworks from hand written stubs.
Can anyone please answer why one would opt for mocking frameworks when they are already doing unit tests...
Hi,
When I use Easymock(or a similar mocking framework) to implement my unit tests, I'm forced to do interaction-based testing (as I don't get to assert on the state of my dependencies. Or am I mistaken?).
On the other hand if I use a hand written stub (instead of using easymock) I can implement state based testing.
I'm quite unclea...
I'm attempting to write some unit tests using EasyMock and TestNG and have run into a question. Given the following:
void execute(Foo f) {
Bar b = new Bar()
b.setId(123);
f.setBar(b);
}
I'm trying to test that the Id of the Bar gets set accordingly in the following fashion:
@Test
void test_execute() {
Foo f = EasyMock.create...
I'm a newbie in Unit Test with Mock Object. I use EasyMock. I try to understand this example:
import java.io.IOException;
public interface ExchangeRate {
double getRate(String inputCurrency, String outputCurrency) throws IOException;
}
import java.io.IOException;
public class Currency {
private String units;
privat...