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
5
votes
3 answers

JUnit mocks, which tool should i use?

I come from the PHP testing world and i'm starting testing in Java. I've seen several tools to mock the SUT in JUnit, like Mockito, SevenMock, ClassMock, etc. I really appreciate any recommendation of which one should i use. Thanks in advance!
victorgp
  • 882
  • 1
  • 13
  • 22
5
votes
3 answers

Is there a simple way to match a field using Hamcrest?

I want to test whether a specific field of an object matches a value I specify. In this case, it's the bucket name inside an S3Bucket object. As far as I can tell, I need to write a custom matcher for this: mockery.checking(new Expectations() {{ …
Kevin Peterson
  • 7,189
  • 5
  • 36
  • 43
5
votes
2 answers

java.lang.VerifyError with Mockito 1.10.17

I am trying to replace JMock with Mockito (1.10.17). I have already done some unit tests successfully, but now I want to use the timeout feature verify(publisher, timeout(5000)).notifySubscribers(any(BecameMasterMessage.class)); and I get this…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
5
votes
3 answers

Using Spring JUnit4 and JMock together

When I run my Junit4 tests now I use the @RunWith(SpringJUnit4ClassRunner.class) annotation which allows me to inject Spring Beans into my test class. I would like to use the JMock 2 framework (which I have no real experience of) but examples I see…
Rich Mischook
  • 61
  • 1
  • 3
5
votes
4 answers

Check if a method was called inside another method

Is there any way in java to check if a certain method was called inside another method? I am testing a class and the method I am having trouble with plays sound and there is virtually no way of getting the audio file that is played(private attribute…
user2337029
  • 627
  • 1
  • 6
  • 11
5
votes
4 answers

How to unit test a class which extends/inherits a 3rd party class

I have created a new class which extends a 3rd party abstract class. The new class calls methods in the abstract class. The problem I have is when trying to write the unit test, I'm not sure how to write a test as I would not know the exact details…
Ilyas Patel
  • 400
  • 2
  • 11
  • 27
5
votes
3 answers

Mock a superclass constructor

I would like to know if I can mock a super class constructors call and its super() calls. For example, I have the following classes class A { A(..) { super(..) } } class B extends A { B(C c) { super(c) …
Rishi
  • 1,331
  • 4
  • 13
  • 16
4
votes
2 answers

jUnit + jMock and log4j

I've given a task to do a JUnit + JMock on a program created by other programmer. Most of the class has this static field logger, i.e.: static Log logger = LogFactory.getLog(SomeClass.class.getName()); I am creating an instance of SomeClass by…
Zorlac
  • 83
  • 1
  • 8
4
votes
1 answer

Can you mock out method calls in the class you're testing?

I'm trying to write JUnit tests for my code but with in some of my methods other methods are called. Is it possible to mock these calls out? E.g. s3FileWrite(File file, Status status) { S3 s3 = new S3(file.getName, s3Service) String key…
Alexei Blue
  • 1,762
  • 3
  • 21
  • 36
4
votes
3 answers

Hamcrest matcher for a String, where the String contains some random values

Is there a way to match the following string with any of the hamcrest matchers. "{\"messageType\":\"identify\",\"_id\":\"7de9a446-2ced-4bda-af35-81e95ad2dc32\",\"address\":\"192.168.0.0\",\"port\":7070}" This string is passed to a method. I use…
Kiril Kirilov
  • 11,167
  • 5
  • 49
  • 74
4
votes
2 answers

Mock/Test Super class call in subclass..is it possible?

I am looking for a solution to mock the super call in subclass ButtonClicker. Class Click { public void buttonClick() throws java.lang.Exception { /* compiled code */ } } Class ButtonClicker extends Click { @Override public void…
Himalay Majumdar
  • 3,883
  • 14
  • 65
  • 94
4
votes
1 answer

jmock - mocking a method with long[] as input and with(any())

I have a question related to jmock library. I am trying to mock a method that has a parameter of long[] and with(any()). Is there a direct way to do that? public class A { public void Method_A(long[] a) { //Do Somthing. need to mocking } }
Sami
  • 1,369
  • 14
  • 35
4
votes
2 answers

Comprehensive Pros/Cons of Mocking Frameworks for GWT

I'm interested in using the right mocking framework for my GWT app. It's my understanding that Mockito, EasyMock, and jMock are some of the most popular for Java. Could someone list pros/cons for the mocking framework that they are most familiar…
JP Richardson
  • 38,609
  • 36
  • 119
  • 151
4
votes
1 answer

setting rspec expectations on internal java method calls from jruby

I would love to be able to test java code with rspec under jruby, but can't see how to set expectations on internal java method calls. Given the following java: public class A { public String hi() { return hello(); } public String hello()…
Toby Crawley
  • 617
  • 3
  • 8
4
votes
1 answer

scalamock: Wildcard argument match on subtype

In my class, I have two versions of a method. One takes an Exception, the other a String. class Foo { def method(e: Exception) = ??? def method(s: String) = ??? } In JMock, I can mock a call to a method based on its type. Notice, I'm using a…
Toby
  • 9,523
  • 8
  • 36
  • 59
1 2
3
17 18