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

JMock - Get reference to mocked method parameter

I am writing unit tests with JMock and I have a mocked out void method that updates a list that is passed in as a parameter. Unfortunately, this list is internal to the method I am testing so I have no reference to it. Is it possible to get it from…
Gaʀʀʏ
  • 4,372
  • 3
  • 39
  • 59
0
votes
2 answers

How is Jmock used with HttpSession and HttpServletRequest

I am new to jmock and trying to mock an HttpSession. I am getting: java.lang.AssertionError: unexpected invocation: httpServletRequest.getSession() no expectations specified: did you... - forget to start an expectation with a cardinality clause? -…
SWD
  • 289
  • 1
  • 5
  • 13
0
votes
1 answer

jmock simplest case doesn't work

That's my JMock test: @Test public void testRunModuleOK() { App instance = getInstanceApp(window,logger); Mockery context = new JUnit4Mockery(); final Modulable m = context.mock(Modulable.class); context.checking(new Expectations()…
user2669285
  • 77
  • 1
  • 2
  • 8
0
votes
0 answers

JMock context error

I've set up a JMock context in my JUnit @Before test, something like: context.checking(new Expectations() { { allowing(mockPayload).getContent(); will(returnValue(FileUtils.readFileToByteArray(XML_FILE))); } }); This reads in an xml…
user898465
  • 944
  • 1
  • 12
  • 23
0
votes
1 answer

What is different between @Mock and @Auto. ( Used for creating automatic mock object in JMock)?

Here is sample code to create mock objects automatically. @Mock Mocked-class cheddar; @Auto Sequence events;
AtulSingh
  • 38
  • 6
0
votes
1 answer

How to use Jmock to produce mock Json request?

In our code we get Json object from ActiveMQ and then decide action and other parameter for action and then return Json object to ActiveMQ. To unit test we have to mock Json object request.
AtulSingh
  • 38
  • 6
0
votes
1 answer

Jmock with reflection

I have a requirement where i need to mock the com.sun.deploy.security.DeployManifestChecker and return null when accessing printWarningsIfRequired in that class. Since Deploy.jar is not in my build path, i couldnt directly mock it up. I'm looking at…
user721476
  • 21
  • 1
  • 6
0
votes
1 answer

Testing MultipartForm with multiple file inputs.

I am using Playframework 2.1 with Scala. I would like to test my function , in view part i have to input files. image and music. I am able to test just musicfile perfectly but when it comes to test both of them. I am having…
Ducaz035
  • 3,054
  • 2
  • 25
  • 45
0
votes
0 answers

JUnit add Action to existing one

I have a default action that i want always called when a method is called, like so : @Before public void setUp() throws Exception { context = new JUnit4Mockery() {{ setThreadingPolicy(new Synchroniser()); }}; …
Steinkauz
  • 21
  • 4
0
votes
0 answers

Mock native method with JMock 2

Can I mock a native method with JMock 2? For example, mock this method from the Thread class public final native boolean isAlive(); Writing tests in the usual way just fail with not all expectations were satisfied so it's implying not. It fails…
Toby
  • 9,523
  • 8
  • 36
  • 59
0
votes
2 answers

No tests found using JMock

having problems trying to run by unit test with Ant, my test class uses Jmock; @RunWith(JMock.class) and annotations to identify each test method. When i attempt to build with ant (1.7.1) i get a [junit] No tests found in MyTestClass [junit]…
cdugga
  • 3,849
  • 17
  • 81
  • 127
0
votes
1 answer

Dependencies for jUnit 4.11 with JMock 2.6 and Hamcrest 1.3

I'm using a combination of JUnit 4.8 JMock 2.5.1 and Hamcrest 1.1. Now I wanna upgrade to jUnit 4.11 with JMock 2.6 and Hamcrest 1.3. Cause JUnit 4.11 comes with hamcrest 1.3. I only import JUnit 4.11 and JMock trough my dependency…
user558213
  • 69
  • 1
  • 5
0
votes
1 answer

Anonymous Action classes cause IndexOutOfBoundException

I have some anonymous Action classes in unit test code. Anonymous classes have no name. Class#getSimpleName returns "". It causes IndexOutOfBoundException when initialing convention-plugin. PackageBasedActionConfigBuilder#buildConfiguration skips…
Long Vu
  • 195
  • 1
  • 2
  • 9
0
votes
1 answer

JMock - Object without expectation

I'm using junt and jock. Suppose I have an interface of an object, Contact, and a method like this one in my test class: @Test public void testAddOneContact() { final Contact contact = this.context.mock(Contact.class); …
Fabrizio Duroni
  • 747
  • 1
  • 11
  • 24
0
votes
1 answer

JMock, Getting error

Getting error : java.lang.AssertionError: unexpected invocation: user.setUserName("John") no expectations specified: did you... - forget to start an expectation with a cardinality clause? - call a mocked method to specify the parameter of an…
dvsakgec
  • 3,514
  • 4
  • 28
  • 35