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

Verifying specific abstract constructor of parent is invoked

In the code base I have the following structure: abstract class Bar{ public Bar(){ .... } .... public Bar(int x, int y){ } .... } Bar is then extended by Foo. abstract class Foo extends Bar{ public…
arin
  • 1,774
  • 22
  • 35
0
votes
1 answer

how to generate coverage.xml in jmockit?

I am using Jmockit for my unit tests and I have also included jmockit-coverage.jar in my classpath. Currently it generates the following files under 'coverage-reports' folder:coverage.css,coverage.js,index.html,logo.png,prettify.js But its not…
user864077
  • 247
  • 2
  • 3
  • 8
0
votes
3 answers

Exception thrown while running JUnit tests using maven

I got the following exception while running JUnit tests in Maven. java.lang.IllegalStateException: Native library for Attach API not available in this JRE at…
Sneha Parameswaran
  • 185
  • 1
  • 4
  • 9
0
votes
2 answers

JMockit mock protected method in superclass and still test method in real child class

I am still learning JMockit and need help understanding it. I am testing a class that uses superclass methods. My test gets a null pointer when it attempts to use the superclass method due to code inside it that uses struts action context to get the…
branchgabriel
  • 4,241
  • 4
  • 34
  • 48
-1
votes
1 answer

Can we Mock any object or class but not in Junit

Which mock framework can we use to mock a class or its object. We usually use mocking framework while implementing junit test cases, but how can i mock a class/its's object not in any test case class but a normal class. Is it possible to do so ?
Janvi Kadu
  • 17
  • 1
  • 6
-1
votes
1 answer

Mock a static method used inside a private method without using powermock

I wanted to mock a static method used inside a private method of a class and return a specific value. public class Test { private String encodeValue(String abc) { try { return URLEncoder.encode(...); } catch…
Nila
  • 17
  • 1
  • 3
-1
votes
2 answers

Log Method Calls in Java System Classes

I'm looking for a way to log calls to all methods in java.nio.ByteBuffer. I just want to know which methods are being called. This was possible with JMockit, but as of version 1.47 some infinitely wise individual decided to remove support of private…
Dave The Dane
  • 650
  • 1
  • 7
  • 18
-1
votes
1 answer

How can I inject an @Context-annotated field into a RestEasy @Provider?

With RestEasy in a JBoss container, I have an ExceptionMapper annotated with @Provider, which has access to the HttpServletRequest and HttpServletResponse via @Context annotations, like this: @Provider public class MyExceptionMapper implements…
DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77
-1
votes
1 answer

PowerMockito final Static method calls actual method

I have statements like public void dummyMethod() { CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(RolePolicies.class); ctr.setProvisionedThroughput(new ProvisionedThroughput(30L, 5L)); …
MalTec
  • 1,350
  • 2
  • 14
  • 33
-1
votes
1 answer

JMockit Returns Empty Object class

I am new to JMockit. I am trying to mock a class's method but the property are null. Examples below: WebServiceUtility: @Component public class WebserviceUtility { public SamResponse getSamResponse(Parameters myParam) { return…
Yejin
  • 541
  • 2
  • 15
  • 32
-1
votes
2 answers

Use JMockit to mock Arrays.sort() methods in a class

I try to mock Arrays.sort methods to make sure the implementation in the QuickSort class doesn't make use of Arrays.sort. How can I do this? This is my try, which results in a java.lang.StackOverflowError @Test public void testQuickSort() { …
Sadık
  • 4,249
  • 7
  • 53
  • 89
-1
votes
2 answers

JMockit: IntelliJ vs mvn test command line with surefire - Different behaviors

While implementing a unit test using JMockit with a @Capturing annotation and a Verification block for the "captured" variable I have 2 outcomes: IntelliJ: I can run and debug successfully, validating that the verification behaves…
Beyonder
  • 21
  • 1
  • 5
-1
votes
2 answers

JMockit: Verifying if a fake class method is called

I currently have the following code for testing: public class FakeClass extends MockUp { @Mock public void doSomething() { ... } } void testHandleMetrics() { FakeClass fakeClass = new FakeClass(); try { …
jrphqc
  • 9
  • 3
-1
votes
3 answers

How to mock a function call while initializing a variable in @Tested testObject in junit

I have a class A which has a private integer member b. Here is the structure of the class: public class A { private int b= Integer.parseInt(C.getValue(anyString)); public int getB() { return b; } public void setB(int b) { …
sbajpai
  • 1
  • 3
-1
votes
1 answer

How to mock 0 or 1 invocation with jmockit

@Test public void test() { new NonStrictExpectations() { { aService.method1(anyString); result=abc } }; } I am using Parameterized runner with jmockit. Now method1 of aService may or may not…
Anil Punia
  • 37
  • 3
1 2 3
54
55