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
0 answers

Override expectations in JMockit

I want to override a previously defined expectation in JMockit. This is what I tried (see code below) -- I have a private class where I record all the common expectations and I replay it in various test methods. However, one of my method needs most…
APIgeek
  • 1
  • 2
0
votes
1 answer

Failed to return new Object from mocked types

Help me please to realize what wrong with me and my code. Simple example: public class RollingStockCreation { @Mocked Plant plant; @Mocked RollingStock rollingStockMock; @Mocked WrenchManagerInjection wm; @Test public void…
Random
  • 13
  • 1
  • 5
0
votes
0 answers

How do you return an enum as the mocked expectation with JMockit?

My test requires that one of the dependent mocked methods returns an enum. However, this causes JMockit to throw a ClassCastException. public class MyTest { @Mocked Parameters params; @Test public void test() { new…
dhalsim2
  • 936
  • 2
  • 12
  • 35
0
votes
4 answers

Is it possible to insert module dependency to the beginnig of the classpath in some maven profile?

I'm trying to move out jmockit-coverage-0.994.jar dependency from the project to some profile not active by default, but cannot insert it to the beginning of result classpath from the profile dependencies.
Andriy Plokhotnyuk
  • 7,883
  • 2
  • 44
  • 68
0
votes
1 answer

JMockit: How to mock protected methods?

I'm trying to use JMockit in order to mock a protected method of a class: public class A { protected String say() { return "hi"; } } public class B extends A { public String cry() { return "waaaa " + say(); …
Eyal Roth
  • 3,895
  • 6
  • 34
  • 45
0
votes
1 answer

JMockIt security exception signer information does not match

When running JMockIt and trying to mock an instance in testng that is loaded from a signed jar I get an error along the lines of (in this case of a jetty server): FAILED CONFIGURATION: @BeforeClass startServer java.lang.SecurityException: class…
Mallox
  • 1,469
  • 12
  • 13
0
votes
1 answer

How to mock final instance variable in a class using JMockit

I am trying to use JMockit to do behavior test. In one of the test, I need to call a method in the final object. However, the final object is not initialized (null object) and I don't know how to initialize it in the test (since it is defined…
jgmao
  • 147
  • 2
  • 8
0
votes
0 answers

Multiple interface implementation in Exceptions - JMockit

Iam very new to JMockit and i have a scenario where i have two mock objects created for different interfaces in same Exceptions anonymous class. Is this possible to mock two interfaces and its implementations in same exceptions class.? Have given…
arun_kk
  • 382
  • 2
  • 5
  • 14
0
votes
2 answers

JMockit - Strict Expectation is ignored

I want to test the behavior of a private method. The method "moveDataToArchive" does 4 steps. It's 4x: calculate a date + call a sub method. This is my test: @Test public void testMoveData2Archive() throws Exception{ final long now =…
KFleischer
  • 942
  • 2
  • 11
  • 33
0
votes
1 answer

How to mock a method in JMockit?

For unit testing purpose i need to mock a method which take byte [] as argument.The output will be feed the argument. I want the output as per my requirement. So can anybody help me out with the mocking.
Jeet
  • 157
  • 2
  • 2
  • 4
0
votes
3 answers

Stubbing a static method with JMockit using 'any'

I want to test, whether Collection.sort(...) is called or not with JMockit: final List employees = new ArrayList<>(); new Expectations() { { Collections.sort((List) any); result = employees; …
deamon
  • 89,107
  • 111
  • 320
  • 448
0
votes
1 answer

Use JMockit to test the concrete methods of an abstract class

I have an abstract base class that defines both concrete and abstract methods. I'm wondering if there's a way, using JMockit, to mock this type such that I can declare expectations for the abstract methods and test the implementation of the concrete…
pedorro
  • 3,079
  • 1
  • 24
  • 24
0
votes
2 answers

Excluding files with Maven doesn't work

I run into problems at Maven compile when using JMockit together with JUnit and Android: [INFO] UNEXPECTED TOP-LEVEL EXCEPTION: [INFO] java.lang.IllegalArgumentException: already added: Ljunit/framework/TestResult$1; At least JUnit and JMockit…
Bevor
  • 8,396
  • 15
  • 77
  • 141
0
votes
1 answer

JMockit NullPointerException on mocked object in Expectations

Here is the relevant part of my test case: @NonStrict private StowServiceWrapper mockStowServiceWrapper; @NonStrict private IsItemStowableResponse mockIsItemStowableResponse; @NonStrict private IsItemStowable mockIsItemStowable; ... @Test public…
alexD
  • 2,368
  • 2
  • 32
  • 43
0
votes
1 answer

How do I test a class using JUnit 4 that extends an abstract class?

I am trying to write a unit test for a java class that is extending an abstract class? The java class looks sort of like: public class XYZFilter extends XYZDataFilter{ @Override protected boolean filterItem(Model d, String sector) { …
gjw80
  • 1,058
  • 4
  • 18
  • 36