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
255 questions
18
votes
1 answer

About with(any(Class.class))) with JMock

With JMock: context.checking(new Expectations() {{ // Other oneOf() will() statements ... oneOf(shopAccount).enter(100, with(any(String.class))); will(returnValue(true)); // Other oneOf() will() statements ... }}); The following…
Édipo Féderle
  • 3,799
  • 4
  • 27
  • 31
18
votes
9 answers

Unit test helper methods?

I have classes which previously had massive methods so I subdivided the work of this method into 'helper' methods. These helper methods are declared private to enforce encapsulation - however I want to unit test the big public methods. Is it good…
Aly
  • 14,299
  • 42
  • 109
  • 181
17
votes
6 answers

Can I mock a super class method call?

Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative)…
arielsan
  • 408
  • 2
  • 4
  • 11
16
votes
2 answers

Does JMockit have any drawbacks at all?

This comparison shows, that JMockit has several advantages over other frameworks. Are there also any advantages that one of the others (JMock, EasyMock, Mockito, Unitils, PowerMock + Mockito/EasyMock) has over JMockit?
Chris Lercher
  • 36,020
  • 19
  • 96
  • 128
13
votes
2 answers

Does mockito have an equivalent idiom to jMock's States?

The book Growing Object Oriented Software gives several examples in jMock where the state is made explicit without exposing it through an API. I really like this idea. Is there a way to do this in Mockito? Here's one example from the book public…
Michael Deardeuff
  • 9,345
  • 4
  • 47
  • 67
12
votes
5 answers

Unit testing a Swing component

I am writing a TotalCommander-like application. I have a separate component for file list, and a model for it. Model support listeners and issues a notification for events like CurrentDirChanged etc. in following manner: private void…
Ula Krukar
  • 11,239
  • 20
  • 48
  • 65
12
votes
3 answers

Capturing method parameter in jMock to pass to a stubbed implementation

I wish to achieve the following behavior. My class under test has a dependency on some other class, I wish to mock this dependency with jMock. Most of the methods would return some standard values, but there is one method, where I wish to make a…
Jugal Thakkar
  • 13,328
  • 4
  • 52
  • 78
11
votes
5 answers

JMOCK Dependency Issue

I am trying to get through my very first JMOCK tutorial http://www.jmock.org/getting-started.html, and it didn't go well. The problem I encountered is below: java.lang.SecurityException: class "org.hamcrest.TypeSafeMatcher"'s signer information…
sarahTheButterFly
  • 1,764
  • 2
  • 21
  • 35
11
votes
1 answer

Do any tools use the hamcrest Factory annotation?

I sat down to write a matcher today and decided to take a quick look at the jmock documentation to refresh my memory on the process, and noticed a reference to the org.hamcrest.Factory annotation. The documentation for the annotation states. Marks…
sonstone
  • 637
  • 5
  • 9
11
votes
3 answers

When should we use Mockery vs JUnit4Mockery?

If writing a Java unit test with mocking using JMock, should we use Mockery context = new Mockery() or Mockery context = new JUnit4Mockery() What is the difference between the two, and when should we use which?
Aman
  • 113
  • 1
  • 4
11
votes
2 answers

Mocking Method that Takes a Class Type Argument with JMock

Background: This is a JMock+JUnit specific question (those are the two technologies I must use). Yes, what I want to do can be done with PowerMock, but this is an edge case that doesn't warrant changing of tools. And no, sorry, I'm not asking this…
luis.espinal
  • 9,728
  • 5
  • 35
  • 54
11
votes
3 answers

jmock mocking a static method

I have a static method in my code that I would like somehow to mock. I am using jmock. One way I suppose I could do this is to have "wrapper class" around the static method and mock this but I was hoping for a better solution. I am going about this…
Paul Whelan
  • 15,841
  • 12
  • 46
  • 79
11
votes
1 answer

Does Spring @DirtiesContext reload Spring context?

I have a test class that looks like @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/test-context.xml"}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public abstract class TestClass { @Rule…
ThanksForAllTheFish
  • 6,625
  • 4
  • 32
  • 54
8
votes
3 answers

Standard way to capture arguments in JMock

Is there an already built-in, standard way in JMock to capture method arguments to test the argument object later on with standard JUnit functionality? Something like final CapturedContainercapturedArgumentContainer = new…
Ralph
  • 111,219
  • 48
  • 270
  • 362
7
votes
3 answers

Unit testing using MockMultipartHttpServletRequest (throws NullPointerException in ItemInputStream.makeAvailable)

I've written a transformer class that takes an HttpServletRequest and transforms it into another type that holds a pointer to the InputStream from the servlet request. (The idea is to abstract the incoming transport protocol from the request…
Mike S
  • 89
  • 2
  • 6
1
2 3
16 17