Questions tagged [jmockit]

JMockit is a java framework for mocking objects in JUnit testing. It uses the instrumentation apis that modify the bytecode during run time to dynamically create classes. It allows developers to write unit tests without the testability issues typically found with other mocking APIs. Tests can be written that will mock final classes, static methods, constructors, and so on. The API also provides advanced support for integration tests and code coverage tool.

JMockit is a Java mocking API with expressive recording & verification syntax in JUnit/TestNG testing.

It provides mocking by using instrumentation APIs that modify class bytecode during runtime, allowing developers to write unit tests without the testability issues typically found with other mocking APIs.

Tests can be written to mock final classes, static methods, constructors, and so on. The API also provides advanced support for out-of-container integration testing for Java EE and Spring-based apps and code coverage tool with line and path metrics.

816 questions
0
votes
1 answer

Jmockit: Expectations() works in v12 but not in v13/v14 (Java SE 8, TestNG 6.8.13)

With JMockit v12, this test passes (not the real code, but illustrates the issue): import mockit.Expectations; import mockit.Mocked; import org.testng.Assert; import org.testng.annotations.Test; public class JmockitExperimentsTest2 { public class…
CraftWeaver
  • 707
  • 1
  • 8
  • 21
0
votes
1 answer

JMockit Mocking java.net.URL causes test not run

I'm using the newest versions of junit and jmockit and Oracle JDK 7 in Eclipse. When I try to mock java.net.URL my test won't run. I have in my code something like: URL url = new URL("String representing the url."); So I figured in my test I could…
Mimerr
  • 390
  • 1
  • 5
  • 14
0
votes
1 answer

How to pass a mock to unitundertest with jMockit?

I want to pass a Mock to my unitUnderTest. How can I achieve this in JMockit? See the following code excerpt. @Test public void paymentResponseCreatorTest(){ final ClassUnderTest unitUnderTest = new ClassUnderTest(); MockUp
Marcel Pater
  • 164
  • 10
0
votes
1 answer

JMockit, how do I mock a private method with no returns

I'm trying to mock a private method using JMockit, and struggling. I have been working through the tutorials and can mock private methods that return values nut not without. This particular method interacts with a database and does not return…
John Paul
  • 772
  • 1
  • 6
  • 17
0
votes
1 answer

Access properties of MockUp Classes

I would like to access the requestContext property of the MockUp class instance WebServiceProxyInstance. The property only exists in the mock class and is not part of the implemented interfaces. Is there any way to do this? @Test public…
Philipp Waller
  • 463
  • 1
  • 7
  • 13
0
votes
2 answers

Unable to mock a private method via jmockit

Please help, this mock isn't working : class ClassBeingTested { private AnotherClass anotherClass; public void someMethod() { int ans = anotherClass.targetMethod(5); // Use ans here } } // My test ClassBeingTested…
user1071840
  • 3,522
  • 9
  • 48
  • 74
0
votes
1 answer

Mock private methods of the class under test in jmockit

I want to test process method of the ProcessServiceImpl class, with mocking private methods: readContent and isValidFile and userService class. @Named("processServiceImpl") public class ProcessServiceImpl { @Inject private UserService…
Arya
  • 2,809
  • 5
  • 34
  • 56
0
votes
1 answer

Can't mock EntityManager jMockit

I am having some trouble trying to mock out an EntityManager in tests using jMockit. I have this base class: public abstract class BaseEntityManager { @PersistenceContext private EntityManager entityManager; protected EntityManager…
Matt Williams
  • 1,198
  • 1
  • 10
  • 27
0
votes
1 answer

Why is my JMockit test case not failing when I don't provide the correct expectations on a Strict Expectation?

I am using Jmockit for the firs time so I could be missing something trivial. I have a method under test addTopTenListsTest() which calls --> mockObjectifyInstance.save().entity(topTenList).now(); Objectify is mocked, however when I comment out the…
Saifuddin Merchant
  • 1,071
  • 7
  • 13
0
votes
1 answer

JMockit passing same argument in the mocked method as actual method is getting

I'm trying to write getter and setter mock methods which seem to be doing some database operation internally. Getter returns a String and setter takes String as argument. I would like to pass whatever I get from getter to the setter instead of…
bot15
  • 38
  • 4
0
votes
1 answer

Jmockit - Mocked methods returning interfaces

i have the following setup: public String loadFile(String uri) throws ClientProtocolException, IOException { StringBuilder resp = new StringBuilder(); HttpClient client = HttpClientBuilder.create().build(); HttpGet request =…
billdoor
  • 1,999
  • 4
  • 28
  • 54
0
votes
0 answers

Deencapsulation.invoke method is throwing exception with message "IllegalArgumentException: No compatible method found"

Deencapsulation.invoke() throws exception with message if I pass an instance of subclass as argument to private method java.lang.IllegalArgumentException: No compatible method found. Like this: Object a = new ClassB(); try { …
वरुण
  • 1,237
  • 3
  • 18
  • 50
0
votes
1 answer

JMockIt throws DuplicateExpectation in mvn when a test case has multiple expectations defined for the same static method

I'm trying to mock a web call that returns different results depending on the inputs. My test case is as follows: class RestService1 implements IRestService{ public static String checkSomething(){ return "something"; } } class…
0
votes
1 answer

Aggregate jmockit-coverage output with emma coverage output

Is there a way to aggregate code coverage data from jmockit-coverage and emma coverage? I can run the two different coverage steps in two separate junit ant tasks and generate the coverage data in two directories. Just not sure if the coverage…
ekc911
  • 1
  • 1
0
votes
2 answers

Create dummy objects for classes using JMockit

I'd like to create dummy objects (see definition here) using JMockit. These objects are required as nonnull constructor arguments, but aren't needed for the specific unittest. Because the constructor might check the parameter (e. g. using…
Christian Rudolph
  • 1,145
  • 1
  • 15
  • 22