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

jMockit: How to expect constructor calls to Mocked objects?

I am unit-testing a method performing some serialization operations. I intend to mock the serialization logic. The code is as below: ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file))); I have created…
Nagendra U M
  • 601
  • 2
  • 6
  • 16
5
votes
2 answers

How to prevent super class from being mocked by jmockit?

Given a class hierarchy that looks like this: public class Vehicle { private String name; public Vehicle(String name) { this.name = name; } public String getName() { return name; } } public class Car extends…
rdguam
  • 356
  • 5
  • 10
5
votes
1 answer

How to mock private methods from Jmokit 1.49 version

I am using Junit 3.8.1 and updated Jmokit to 1.49 I have a project in which existing tests present with MockUp. Having private methods mocked. After updating Jmockit jar to 1.49 version getting error as follows java.lang.IllegalArgumentException:…
Tushar Girase
  • 183
  • 4
  • 15
5
votes
1 answer

JUnit 5 tests fail with usage of JMockit dependency. How to tests methods referencing static mehtods

I am converting the unit tests written in JUnit 4 to JUnit 5. We use JMockit when a method being tested makes a call to static method. In JUnit 4, @RunWith(JMockit.class) public class MyTest{ } In JUnit 5 if I add JMocket dependency in pom.xml,…
user679526
  • 845
  • 4
  • 16
  • 39
5
votes
1 answer

Debug Partial Mock in JMockit

Using JMockit 0.999.4 and JDK6, is it possible to debug into a partially mocked class? Consider the following test: @Test public void testClass() { SampleClass cls = new SampleClass(); System.out.println(cls.getStaticInt()); …
ctran
  • 121
  • 1
  • 5
5
votes
1 answer

How to mock static methods in Kotlin?

I'm trying to mock a static method with jMockit in Kotlin: object: MockUp() { @Mock fun getProperty(name: String) = "tagB" } But I get the following error: Could not load Logmanager "tagB" java.lang.ClassNotFoundException: tagB …
deamon
  • 89,107
  • 111
  • 320
  • 448
5
votes
3 answers

JMockit wasn't properly initialized

I am using junit 4.12, jmockit 1.19 & spring-test 4.1.1.RELEASE for testing my Spring MVC Java project. Order of these dependencies in my pom.xml: jmockit junit spring-test Test cases for service layer is working fine. I am using spring-test…
Dev
  • 13,492
  • 19
  • 81
  • 174
5
votes
1 answer

how to mock FacesContext with JMockit, All the tests fail with NullPointerException

All the junit tests fail with NullPointerException when the bean uses FacesContext or creates an object of a class which uses FacesContext. Please suggest a way to test the code with junit. Bean @ManagedBean(name =…
user1926688
5
votes
1 answer

JMockit ERROR - Native library for Attach API not available in this JRE

I have looked for answers to this problem and tried the only solution to this I could find (jmockit: Native library for Attach API not available in this JRE error) I tried adding attach.dll to PATH environment variable with no success.…
SteveK
  • 207
  • 2
  • 6
  • 17
5
votes
1 answer

Mocking static methods with jmockit (1.5) before class

According to the example in the Jmockit tutorial this code should do the trick: @BeforeClass public static void setUpClass() { new MockUp(){ @Mock public static String getDirectoryFromContext(Property jndiName) // line 66 …
adrian.riobo
  • 495
  • 5
  • 11
5
votes
3 answers

How can I unit test Log4j using JMockIt?

When a Logger (Or any static field) is declared in a class using a static method: public class Foo { private static final Logger LOGGER = Logger.getLogger(Foo.getClass); } What is the correct way in which I can assert that methods on it are…
Andrew Stubbs
  • 4,322
  • 3
  • 29
  • 48
5
votes
1 answer

JMockit + Jetty in functional tests

I'm using ShrinkWrap to start Jetty server in my integration tests. Problem: When I start my test jetty-server and than make mockup of my controller - mockup doesn't work! I suggest that the reason is different classloaders: JMockit -…
VB_
  • 45,112
  • 42
  • 145
  • 293
5
votes
1 answer

How do I expect and verify the same method in JMockit

Having the following class: class ToTest{ @Autowired private Service service; public String make(){ //do some calcs obj.setParam(param); String inverted = service.execute(obj); return "<" +…
Jordi P.S.
  • 3,838
  • 7
  • 36
  • 59
5
votes
1 answer

Getting an error when using EclEmma (eclipse plugin) with JMockit (only with Delegate())

I recently started using JMockit and am very new at TDD and mocking. I like to use code coverage to make sure that I have tested all the lines for a given a class/method. I came across the following error when trying JMockit (Delegate()…
Pranav Shah
  • 3,233
  • 3
  • 30
  • 47
5
votes
5 answers

Sonar (jacoco) + jmockit spamming with exceptions

I'm facing a error which starting to be really irritating. Here is what I have: 1) Sonar 3.5 which uses JaCoCo as coverage tool. 2) Jmockit lib to perform testing with use of mocks. 3) Build process automized with maven. So when I run first mvn…
mr.nothing
  • 5,141
  • 10
  • 53
  • 77