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

How to Test Servlet that uses database to login?

Hello guys i want to test this code using mocκito or JUNIT. //Login Servlet @WebServlet("/login_controller") public class login_controller extends HttpServlet { private static final long serialVersionUID = 1L; private String TAG="Login…
0
votes
1 answer

Mocking classes against a running RESTeasy server

I have a RESTeasy service I would like to test against a running server (in this case I don't want to use the mock framework from RESTeasy. However, I would like to validate the service without the need to create "real" data so I would like to…
0
votes
1 answer

junit runs fine when run with gradle on command line but fails to run on eclipse as a junit test

junit runs fine when run with gradle on command line but fails to run on eclipse as a junit test. Why?? All tests pass with command: gradlew clean test on commandline but fail on eclipse when RunAs -> Junit I am using jmockit as mocking framework in…
Neeraj
  • 592
  • 4
  • 6
  • 21
0
votes
1 answer

JMockit consecutive expectations

I recently came across with the issue explained below and I could not find an explanation for it. My code under test looked OK but the test was failing. It took me a while to understand what was wrong especially as my code under test was not as…
Julian
  • 3,678
  • 7
  • 40
  • 72
0
votes
0 answers

How to mock an invisible class with JMockit?

package pack1; class ClassToBeTest{ private void method1(){ boolean check = method2(); } private boolean method2(){ return false; } } package pack2; public class TestClass{ @Test public void…
0
votes
1 answer

Jmockit getting null pointer exception on unit testing (testng) a getter method

I have the following code //Unit to be tested (classname : PropertiesFile) public static String getProperty(String name) { return propertiesMap.get(name).toString(); } where propertiesMap is a normal hashmap defined as Map…
Saumya A
  • 11
  • 3
0
votes
1 answer

Objects behave weird when mocking private method of class under test using jmockit

Instance object of my class under test behavior varies when I tried to mock private method of my class. I have object of my CUT which I am initializing in @Before setup method @Before public void setUp() { cutInstance = new CUT(); and in my…
User12001
  • 23
  • 3
0
votes
1 answer

How to partially mock a dependency abstract object in JMockit

I have abstract class D which is a dependency of the tested class T. The test class: public class T_Test { @Tested T tested; D dependency; public void test() { dependency.doSomething(); tested.testedMethod(dependency); …
Dikla
  • 3,461
  • 5
  • 30
  • 43
0
votes
2 answers

Problems with setting up a trivial jmockit test with maven

Today I've spent some non-zero time trying to setup a simplest maven project that will run a simplest jmockit test. While trying to write such an xml, I've faced with several problems, starting with java.lang.NoClassDefFoundError:…
Andrew Krasny
  • 71
  • 2
  • 4
0
votes
1 answer

Using another object as parameter in Jmockit Mocked object

I'm new to JMockit and have successfully run a basic unit test using it. However, I'm stuck when attempting to mock a Spring LdapTemplate. The problem seems to be with the LdapQuery that is used by the LdapTemplate. Do I need to mock this as…
acvcu
  • 2,476
  • 10
  • 40
  • 56
0
votes
1 answer

How to mock out InetAddress.getLocalHost() using JMockit

The InetAddress constructor is not visible because the factory pattern is used. final InetAddress anyInstance = InetAddress.getLocalHost(); new NonStrictExpectations(InetAddress.class) { { anyInstance.getHostAddress(); …
johnjamesmiller
  • 720
  • 5
  • 14
0
votes
3 answers

How to mock a CQ5 Page object containing a cq5 tag

I have a method on which I'd like to run a JUnit test. I'm mocking the cq5 page using JMockit. My test method looks like this @Mocked Page page; @Mocked PageManager pageManager; Tag testTag =…
bongman1612
  • 440
  • 1
  • 11
  • 23
0
votes
0 answers

Mock native objects

I'm using Robolectric and Mockito for Unit Testing. The current setup is working out great for me but I have code that is heavily dependent on a library that is calling a native dependency. I'm aware that I cannot mock native method calls using…
Jani
  • 1,400
  • 17
  • 36
0
votes
1 answer

Partial mocking class under test

I'm looking to mock a static method of a support class and in order to do that, I need to mock a method of the class under test using jMockit. IN the example below, I want mock the method canContinue in order to always get inside the if condition. I…
John
  • 619
  • 2
  • 9
  • 24
0
votes
1 answer

Java constructor mockup

Could you please any one tell me How to mock up Java Constructor ? I tried as below. But it doesn't work. new MockUp() { @Mock public UserCompanyDivision(String com, String div) { } };
sujan duminda
  • 31
  • 1
  • 6