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

Null Pointer Exception in mocking Interface method

I'm using TestNG for testing and JMockit for mocking mockMethod(). Here's the test case: @Test public void testClass1() { new MockUp() { @Mock public int myMethod(final MyObject someObject ){ return 0; } …
user2281204
  • 81
  • 1
  • 3
  • 13
0
votes
0 answers

Mocking parameterized constructor using junit

I need to construct a test case for a method which needs an instance of SomeClass as below: class ClassToTest { ... ... public boolean testMethod (SomeClass instance) { .... } ... } …
user2281204
  • 81
  • 1
  • 3
  • 13
0
votes
0 answers

Android: Verifying behavior using Unit Tests

So let's say I have a simple activity as follows. Assume all of the the lifecycle events etc. are correctly created there's no exception in creating an activity. public class ButtonClickActivity extends Activity implements OnClickListener { ...…
adrian
  • 2,326
  • 2
  • 32
  • 48
0
votes
1 answer

Is it correct to pass two classes as arguments in NonStrictExpectations in JMockit?

Can we pass more than two class aruments in NonStrictExpectations. Like this NonStrictExpcetations(A.class, B.class)
Varun
  • 209
  • 2
  • 5
  • 11
0
votes
1 answer

jmockit testing fake http response

In my class I have a method doRequest(HttpRequest, someListener) that sends a HttpRequest and use the listener to handle the returned HttpResponse. Based on different responseCode 500, 203, etc, the handle method will call different method A(), …
0
votes
1 answer

Running EMMA with JMockit and JUnit in Maven

I have a problem when running EMMA code coverage tool with JMockit + JUnit in maven. I have a project and I am using JMockit as a mocking framework in it. Once I run mvn test it is running successfully without any problem. That’s means JMockit is…
gbids
  • 489
  • 1
  • 6
  • 16
0
votes
1 answer

List of MockUp instances

I am looking for the way to create list of mocked instances that returns different values, based on arguments provided in constructor. public interface ValueObject { int getValueInt(); String…
Andrii Liubimov
  • 497
  • 4
  • 12
0
votes
1 answer

JMockit: Expectation seems to be looking for exact instance when using @Mocked

I have a method that does something like this: public void registerNewFoo( String someId ) { Foo foo = m_fooList.getFoo( someId ); if ( foo != null ) { // do something return; } // create new foo foo = new…
Kevin
  • 702
  • 7
  • 22
0
votes
1 answer

Stopping mocking in Jmockit

I am using JMockit. I am mocking a method. I want that mocked method should be called once after that actual method should be called. I am providing the code I am using. package StopMocking; public class ClassToMock { public int methodToMock() …
Varun
  • 209
  • 2
  • 5
  • 11
0
votes
1 answer

How to mock public void method using jmockit?

I am trying to write some junit test for my Spring MVC controller and so far I am able to do it successfully. I am using Spring Mock along with jmockit as well. Below is my method in the DataController controller - @RequestMapping(value =…
john
  • 11,311
  • 40
  • 131
  • 251
0
votes
2 answers

Android + jmockit: java.lang.VerifyError: mockit/internal/startup/Startup

I got an error below when I try to change from Calendar class to a mock class by using jmockit(version1.8). Doen anyone know how to fix it ? Any help will be appreciated. Thanks, CalendarMock.java import java.util.Calendar; import…
zono
  • 8,366
  • 21
  • 75
  • 113
0
votes
2 answers

JMockit: howto invoke custom method of MockUp

My application use FastScanner (based on BufferedReader) to read input (Look at code section of my question). If I want to substitute input in my tests I should mock up FastScanner (Look at code section of my question). Problem: For each input I…
VB_
  • 45,112
  • 42
  • 145
  • 293
0
votes
2 answers

JMockit hang on in unit tests

I use JUnit for unit-testing. I use JMockit to mock up some java.util classes in my unit tests: new MockUp() { //HERE UNIT TESTS HANG ON @SuppressWarnings("unused") @Mock(invocations = 5) public void…
VB_
  • 45,112
  • 42
  • 145
  • 293
0
votes
1 answer

Remove NonStrictExpectation which was defined previously

I have this NonStrictExpectation in my JUnit test case: new NonStrictExpectations(mCurrencyDao) { { invoke(mCurrencyDao, "readSqlQuery", withAny(String.class)); result = prepareTestSQL(pAllKeysForTest); times = 1; …
nano_nano
  • 12,351
  • 8
  • 55
  • 83
0
votes
1 answer

How to mock instantiating a new object with any not null parameter with JMockit

I would like to mock the new instance of java.io.File with any not null parameter with JMockit. Here is the code newInstance("java.io.File", (String) withNotNull(), (String) withNotNull()); But it keeps saying Invalid null value passed as argument…
Truong Ha
  • 10,468
  • 11
  • 40
  • 45