You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have encountered an issue when using @capturing. It is related to Spring,Apache CXF, the version of JMockit and also the sequence of running tests.
The issue is very obscure, but I have a concise set of files available that is a full maven project that demonstrates the problem. I have tried to put these at the end of the issue, but can send these if needed.
The business model is:
An interface ITestObject - Containes a single method that helps to identify when the problem arises.
A class TestObjectContainer - A java bean that has a single property of type ITestObject
A class TestObject that implements ITestOject
The testing performed is:
FirstTest - A Junit test class with a single test method that simply loads a spring XML context file first-test.xml and closes the context
SecondTest - A Junit test class with a single test method that
Gets a named bean from the context of type TestObjectContainer
Checks that the contained ITestObject bean is mocked.
The environment is:
Windows 7
Java 8
JUnit 4.12
Spring 4.1.6 Release
JMockit - 1.6 or 1.16 (we had been using 1.6 and tried 1.16 when problems arose)
CXF 3.0.4
Eclipse Luna
Setup A
JMockit 1.6 (This was the version we were using when we first encountered the problem.
The first-test.xml configuration has a TestObjectContainer bean containing an ITestObject that is actually a CXF proxy client for a web service.
The second-test.xml configuration also has a TestObjectContainer bean containing an ITestObject that is actually a CXF proxy client for a web service.
Scenario A1
Run SecondTest on its own - PASS - confirms the ITestObject is mocked.
Scenario A2
Run FirstTest then SecondTest as a single execution (I selected the package to run) in eclipse (It is hard to know what order eclipse/junit will run the tests) - SecondTest FAILs - it is attempting to connect with the CXF client proxy.
Setup B
As setup A, but instead of first-test.xml having a CXF client proxy, it has a POJO of type TestObject
Scenario B1
Run FirstTest then SecondTest as a single execution in eclipse -PASS
Setup C
JMockit 1.16
The second-test.xml configuration has a TestObjectContainer bean containing an ITestObject that is actually a CXF proxy client for a web service.
Scenario C1
Run SecondTest on its own - FAIL (This passes on JMockit 1.6)
Setup D
JMockit 1.16
The second-test.xml configuration has a TestObjectContainer bean containing an ITestObject that has a POJO of type TestObject.
Scenario D1
Run SecondTest on its own - PASS
So, trying to summarise the factors involved:
Using a CXF bean rather than a POJO causes failure (Scenarios A2 -> B1 and C1 -> D1)
Running tests in isolation or as part of a set of tests causes failure (A1 -> A2)
Using the latest JMockit can cause a failure (A1 -> D1)
Apologies for the length of post and amount of detail, but hopefully will aid diagnosis.
What happens here is that dynamically generated classes are intentionally excluded from being mocked by a @capturing mock field. And in this case, a "sun.com.proxy.$Proxy8" is generated at runtime; this is a proxy class which implements ITestObject; it has a null class loader and a null protection domain. JMockit automatically excludes all such classes from consideration, to avoid potential cases of unintended mocking. Note the generated proxy class does not extend "TestObject", which would get mocked if it was eventually loaded during the test; but it's not.
So, this is a limitation of the @capturing feature; it only mocks "normal" classes that get loaded from a ".class" file. The limitation could be easily eliminated, but doing so could bring unforeseen consequences.
I will do some experiments to see if dropping the restriction on capturing dynamic proxy classes causes problems or not.
I have encountered an issue when using @capturing. It is related to Spring,Apache CXF, the version of JMockit and also the sequence of running tests.
The issue is very obscure, but I have a concise set of files available that is a full maven project that demonstrates the problem. I have tried to put these at the end of the issue, but can send these if needed.
The business model is:
An interface ITestObject - Containes a single method that helps to identify when the problem arises.
A class TestObjectContainer - A java bean that has a single property of type ITestObject
A class TestObject that implements ITestOject
The testing performed is:
FirstTest - A Junit test class with a single test method that simply loads a spring XML context file first-test.xml and closes the context
SecondTest - A Junit test class with a single test method that
The environment is:
Windows 7
Java 8
JUnit 4.12
Spring 4.1.6 Release
JMockit - 1.6 or 1.16 (we had been using 1.6 and tried 1.16 when problems arose)
CXF 3.0.4
Eclipse Luna
Setup A
Scenario A1
Run SecondTest on its own - PASS - confirms the ITestObject is mocked.
Scenario A2
Run FirstTest then SecondTest as a single execution (I selected the package to run) in eclipse (It is hard to know what order eclipse/junit will run the tests) - SecondTest FAILs - it is attempting to connect with the CXF client proxy.
Setup B
As setup A, but instead of first-test.xml having a CXF client proxy, it has a POJO of type TestObject
Scenario B1
Run FirstTest then SecondTest as a single execution in eclipse -PASS
Setup C
Scenario C1
Run SecondTest on its own - FAIL (This passes on JMockit 1.6)
Setup D
Scenario D1
Run SecondTest on its own - PASS
So, trying to summarise the factors involved:
Apologies for the length of post and amount of detail, but hopefully will aid diagnosis.
Many thanks,
Brian.
Files
src/main/java/com/example/ITestObject.java
src/main/java/com/example/TestObject.java
src/main/java/com/example/TestObjectContainer.java
src/test/java/com/example/FirstTest.java
src/test/java/com/example/SecondTest.java
src/test/resources/first-test.xml
src/test/resources/second-test.xml
pom.xml
The text was updated successfully, but these errors were encountered: