Questions tagged [jmock]

For questions about using jMock. JMock is a helper framework for test-driven development and unit testing.

According to the jMock project website,

JMock is a library that supports test-driven development of Java code with mock objects.

Mock objects help you design and test the interactions between the objects in your programs.

The jMock library:

  • makes it quick and easy to define mock objects, so you don't break the rhythm of programming
  • lets you precisely specify the interactions between your objects, reducing the brittleness of your tests
  • works well with the autocompletion and refactoring features of your IDE
  • plugs into your favourite test framework
  • is easy to extend
257 questions
0
votes
0 answers

Mocking HttpServletRequest using JMock

I am trying to Unit Test a method for which I need to create the object of the class using a constructor.This is how the constructor looks like : public WebformsClinEventBusiness(Webform webForm, String dataEntryModel, String obsBatId) …
userx
  • 1,083
  • 5
  • 18
  • 36
0
votes
0 answers

jmock oneOf not called

I have a class under test with jmock and I was making a change to it and expecting it to fail but it didn't. Before my change I had a alert() method that was getting called as expected and the test was passing. After I made the change my alert()…
naumcho
  • 18,671
  • 14
  • 48
  • 59
0
votes
1 answer

Jmock Loop Consecutive Calls

Is there any way to setup JMock's onConsecutiveCalls method to loop back to the first Action passed once it reaches the end of the list of parameters passed? In the sample code below, I would like the mock to return true->false->true->Ad…
AnthonyW
  • 1,910
  • 5
  • 25
  • 46
0
votes
1 answer

JMock using mocked objects with concrete a class

I have an object with no interface (I can't change this), I was able to mock it using Mock mockedClass = mock(ObjectExample.class, "returnObject", new Class[ ]{java.lang.Integer, java.lang.Integer}, new Object[…
Matt C
  • 137
  • 1
  • 3
  • 15
0
votes
1 answer

What does the with() method of jMock do?

I see with() method being used with assertThat() method in test driven development, but I don't understand what with() does. Could somebody explain with a clear example. I can't seem to find anything on it. Thank you.
T L
  • 39
  • 1
  • 2
  • 6
0
votes
1 answer

JMock HttpServletRequest set parameter

How do I set parameters into my HttpServletRequest in JMock? I search around the Google, many are old and the methods deprecated. The official website is only telling me how to use the tools but it doesn't state how to set parameters for…
lannyboy
  • 617
  • 1
  • 10
  • 20
0
votes
1 answer

JMock and Scala - unexpected invocation error

I'm new to JMock and trying to get a simple unit test working through Scala. The test is mocking an interface and then setting some xpectations before executing a method on the mocked interface. val context = new Mockery val mockObj=…
cdugga
  • 3,849
  • 17
  • 81
  • 127
0
votes
1 answer

How to mock static method using junit and easymock

The problem is next: I need to test method methodTest() of private class. The methodTest() call static method staticExternal() from external library. How to replace the staticExternal() on a mockLocal(), if I use JMock and EasyMock, but class that…
blackhard
  • 502
  • 7
  • 26
0
votes
1 answer

Jmock, Spring and anotated resources in testing

I write controller tests for Spring with Jmock. The controllers use interfaces for database operations. These are service classes. I can jmock them and pass them to controller in test via setter. Real controller has a service marked with…
mjgirl
  • 1,214
  • 7
  • 24
  • 42
0
votes
3 answers

Mock a static method

I want to write a test case that will verify a method in my class. I have a local ApplicationLauncher object in my method that has to be mocked because it calls a method, launch(), which should not be called in a unit test. public class RunApp { …
buttowski
  • 4,657
  • 8
  • 27
  • 33
0
votes
1 answer

NullpointerException when testing a controller method

Here is a controller method I'm about to test with JUnit and JMock. public String myMethod(ModelMap model, Principal principal, @PathVariable MyObject obj) { if (obj != null) { Student student = getStudent(principal); …
mjgirl
  • 1,214
  • 7
  • 24
  • 42
0
votes
1 answer

How to make a "nice mock" by using JMock?

Is there the best way to make nice mock by using JMock? For example: public interface Dependency { void someSetUp(); void interactionUnderTest(); void someCleaningAfterWork(); } public class CUT { private Dependency dependency; …
d3rzKy
  • 142
  • 2
  • 9
0
votes
1 answer

Getting started with JMock and Spring 3

I have started to study JMock. My goal is to write JUnit tests for Spring application, a.k.a controllers and domain classes. In controllers data from database and other services is put to models. I need to make sure that the data is persistent for…
mjgirl
  • 1,214
  • 7
  • 24
  • 42
0
votes
1 answer

JUnit - assertion erros are not propagated

I am experiencing a certain bug in JUnit/JMock. I am trying to mock a couple of objects and then assert that all expectations is satisfied. I am running a simple test such as : @Test public void sellingPutOptionProductDoesNotCauseDisclosure() throws…
Bober02
  • 15,034
  • 31
  • 92
  • 178
0
votes
1 answer

Why does this TestNG test pass although the mock method is not invoked?

I user TestNG and jMock for my unit test but, I have a problem with TestNG. It marks the test as passed when I expect mock object method to be invoked and it is not! public class SomeTestTest { Mockery mocker = new Mockery(); SomeInterface…
Adelin
  • 18,144
  • 26
  • 115
  • 175