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 unable to capture spring data jpa repository calls

By using JMockit @Capturing, it was unable to capture call to any spring data jpa repository methods. public interface UserRepository extends JpaRepository { UserEntity findByName(String name); } public class…
kenn3th
  • 1,187
  • 2
  • 22
  • 47
0
votes
1 answer

How to increase the conditional coverage using jmockit for cobertura?

I am trying to increase the code coverage for following below method using jmockit - Below is my method in DataLogger class for which I am trying to increase the coverage - public void logDebug(final Object... objects) { if…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
0
votes
1 answer

Delegate method doesn't work at Jmockit Unit Test

I just want to setAttribute from the HttPServletRequest. Here's the code snippet for the Jmockit. new Expectations() { private final Delegate requestAttributeDelegate = new Delegate() { final Map attributes =…
lannyboy
  • 617
  • 1
  • 10
  • 20
0
votes
1 answer

UnexpectedInvocation while mocking a static method call

I am trying to test a static method using JMockit. This method uses a utility class static method. When the test runs, JMockit complains and throws the following exception: Test set: com.company.pkg.subpkg.mylib.test.ServiceCommunicationTest …
sgsi
  • 382
  • 1
  • 8
  • 18
0
votes
1 answer

invoke own private method for the result in jmockit

I got this code in my junit: new NonStrictExpectations(mPersonEvaluator) { { invoke(mPersonEvaluator, "doEvaluatePerson", withAny(String.class), withAny(Integer.class), withAny(Integer.class)); result = doEvaluatePerson((String)any,…
nano_nano
  • 12,351
  • 8
  • 55
  • 83
0
votes
1 answer

Static mocked objects in JMockit

Consider a test as below - public class TestSomething { @Mocked static SomeObject mocked; @Test public void testSomething() { new expectations() {{ mocked.doSomething(); }}; …
Gautham J
  • 23
  • 3
0
votes
1 answer

JMockit - Code coverage for partially mocked class under test

I am using jmockit to test out a class which has some complex dependecies. I have marked this class as @Mocked in the test. The test runs fine. I generate a jacoco html report from the output. I do not see any coverage for the "Mocked" class under…
kira
  • 97
  • 1
  • 11
0
votes
1 answer

JMockit: Mocking all implementations of an interface

Is it possible to mock all implementations of an interface? I want to mock the WatchService interface like the following public class ServiceTest { @Test public void callTest( @Capturing @Injectable final WatchService ws )…
rpvilao
  • 1,116
  • 2
  • 14
  • 31
0
votes
1 answer

How to use JMockit to mock Groovy method that takes in a Closure parameter?

I have the following code: def method() { try { dependency0.call({ arg -> }) } catch { dependency1.call() } } and the following test: @Test void shouldDoSomething( @Mocked final Dependency0 dependency0Mock) { …
Noel Yap
  • 18,822
  • 21
  • 92
  • 144
0
votes
1 answer

Mocking my sqlite database

I am junit testing portions of my android app. I'm new to Android and my team is new to unit testing. (Sigh!!!) So I want to grab our custom database adapter, and replace the Sqlite Database with a mocked one created using jmockit. When I try this,…
Thom
  • 14,013
  • 25
  • 105
  • 185
0
votes
1 answer

Expectations are not recorded for injectable instances

Here is my code and I am doing code coverage testing public class RegisterTest { @Tested Register register; @Test public void testGetStudentName(@Injectable final Student student) { new NonStrictExpectations(){ { …
Magesh
  • 427
  • 3
  • 12
0
votes
1 answer

java.lang.NoSuchMethodException with JMockit 1.5 and Robolectric 2.2

I'm trying to use JMockit 1.5 with robolectric 2.2 but I get a java.lang.NoSuchMethodException as soon I try to create an Activity. I've reduced the test to this: @RunWith(RobolectricTestRunner.class) //@RunWith(MyTestRunner.class) public class…
Ignacio Martin
  • 264
  • 2
  • 11
0
votes
2 answers

In JMockIt, what is a @Mock final parameter

I'm completely new to JMockIt. In the tutorial I see example codes that uses the final modifier for a @Mocked parameter e.g. @Test public void doSomethingHandlesSomeCheckedException(@Mocked final DependencyAbc abc) throws Exception { …
JavaMan
  • 4,954
  • 4
  • 41
  • 69
0
votes
2 answers

Excluding multiple packages from code coverage JMockit

I am doing code coverage Testing using jmockit. I need to exclude some classes from code coverage. The VM argument used to exclude classes in eclipse is -Djmockit-coverage-excludes=com\.jmockit\.beans\..+ I referred this documentation. What I need…
Magesh
  • 427
  • 3
  • 12
0
votes
1 answer

jmockit expectations NPE

I have this piece of code: new Expectations(){ { mFubar.getModel(); result = new Model(); times = 1; mFubar.getModel().getAllDogs(); result = new HashSet(); times = 1; } }; Unfortunately I always get a null…
nano_nano
  • 12,351
  • 8
  • 55
  • 83