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 generate coverage report from command line

I have the following command : java -javaagent:jmockit.jar -cp ./out:junit.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore TestCompareNumbers where TestCompareNumbers is my test class for which i want a coverage report. The result is : …
lucian.marcuta
  • 1,250
  • 1
  • 16
  • 29
0
votes
1 answer

Jmockit in JBoss

In a jboss service I need to mock some inner class (not EJB) with JMockit. Just for tests I've created inner class ToBeMocked and another one Mock. While deploying to jboss I get error NoClassDefFoundError in line: Mockit.setUpMock(ToBeMocked.class,…
Filip
  • 433
  • 1
  • 5
  • 7
0
votes
2 answers

How mock method in a Mocked object with JMockit?

I want to create a testcase to test it the authorization is valid or not when I call the service. I Mock my service that will create a new Person. The service will do some logic and validation before persisting the Person in the database. One of…
Sebastien Dionne
  • 757
  • 2
  • 19
  • 34
0
votes
1 answer

Eclipse generate "allocated object never used" errors in jmockit test

Using JMockIt 1.12 and Eclipse Luna and I get "The allocated object is never used" errors. I tried: @Test public void testNullCase() { new NonStrictExpectations() {{ TestClass.getPlug(); result = null; } ... …
Mag
  • 146
  • 1
  • 13
0
votes
1 answer

jmockit issue when mocked class contains method returning Integer

JMockit is not returning the Integer set as the return value in an expectation. public interface Foo { Integer getInt(); } @Test public void test(@Mocked final Foo foo) { final Integer anyInt = 3; new Expectations() {{ …
beluchin
  • 12,047
  • 4
  • 24
  • 35
0
votes
1 answer

Is it possible to use JMockit's Deencapsulation API to exchange method implementation?

So, basically, a there is some poor code that I cannot change that needs to be tested. Traditionally, you inject your mocked dependencies, but with this code, I cannot do so, because there are no setter methods. Worse, the function I need to test…
Adam Miller
  • 1,756
  • 1
  • 25
  • 44
0
votes
1 answer

JMockit MockUp for method with private class parameter

I'm writing some unit tests using JUnit and JMockit and need to write a JMockit MockUp for a method that takes an instance of a private enum as an argument. Here's the the class I need to mock: public class Result { //Static constants…
rphutchinson
  • 514
  • 1
  • 4
  • 8
0
votes
1 answer

JMockit tests are being skipped when running them with Maven

When running my TestNG test https://github.com/AffanHasan/reference-artifacts-repository/blob/master/javase/office-desktop/src/test/java/task_item/TaskItem_behaviorTest.java containing JMockit @Mocked objects it is skipping those tests which…
Affan Hasan
  • 334
  • 1
  • 4
  • 16
0
votes
1 answer

MissingInvocation of Expected static method with mocked instance parameter

I am using JMockIt 1.8, and I have the following classes: public class SimpleUser { public static void useSimple(final SimpleClass simple) { System.out.println("useSimple called"); } public void createAndUse() { final…
Andrew Stubbs
  • 4,322
  • 3
  • 29
  • 48
0
votes
1 answer

How to mock up the EntityManager using jmockit's Mockups API?

I have a problem with mocking up the EntityManager. Everything compiles, the test runs but the mocked method returns null. When I set the breakpoint inside the mocked 'find' method the app is never suspended there. I managed to successfully mock…
Marcin Roguski
  • 729
  • 2
  • 7
  • 16
0
votes
1 answer

Mocking class with existing class in JMockit (replacement for `redefineMethods`)

I've got two classes as input and want to mock one with the other. That used to be very simple in JMockit, one just called Mockit.redefineMethods(originalClass, mockingClass); But in version 0.999 this deprecated method was removed. I need…
Alfe
  • 56,346
  • 20
  • 107
  • 159
0
votes
2 answers

Mocking with JMockit throws NullPointerException on local variables of internal classes

I'm trying to mock a method that creates a local variable, tries something, and does logging if an exception is thrown. Here's a snippet of code: public void myFunction() { //Some stuff try { new File("foo").getAbsoluteFile(); }…
Thunderforge
  • 19,637
  • 18
  • 83
  • 130
0
votes
1 answer

Issue with org.mockito.Matchers.any() and jmockit

I have one UT using jmockit and mockito in this UT,I have one field @Tested TestService testService testService have one method using Car as parameter : testService.doTest(Car car) then my UT: testService.doTest(any(Car.class)) when I debug this UT…
revivn
  • 73
  • 7
0
votes
2 answers

Newbie jMock Q: Test method argument is any string that begins with a given prefix

I have a mock object which expects that a method on it is called. How do I make sure that the string argument it expects begins with particular prefix? oneOf(mockObject).methodName(with(any(String.class));
Debajit
  • 46,327
  • 33
  • 91
  • 100
0
votes
1 answer

UnsupportedClassVersionError while using Jmockit in a Java 1.5 Project

I am trying to use JMockit in a JUnit test, but I am getting an UnsupportedClassVersionError while running the tests from Eclipse. This is a Java 1.5 project and I have JDK 1.5.0.22 in build path and the version of JUnit in class path is 4.11…
Karthik
  • 137
  • 8