Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting MockitoException when running generated tests along with human written tests #268

Closed
rogeriogentil opened this issue Aug 20, 2019 · 1 comment

Comments

@rogeriogentil
Copy link

Context

I want to integrate EvoSuite generated tests to run together human written tests. Some of the human written tests use Mockito. The generated tests are kept separate from human written tests into src/test/evosuite/ folder (following to tutorial available on http://www.evosuite.org/documentation/tutorial-part-2/).

OBS: This issue is similar to #176 (closed).

Steps to Reproduce

I created a POC project to test the behavior.

  1. Clone https://github.com/rogeriogentil/evosuite-junit-mockito-sample
  2. Execute mvn evosuite:generate && mvn evosuite:export && mvn evosuite:prepare test

EvoSuite Arguments

Complete command to reproduce behavior:

cd ~ && rm -rf evosuite-junit-mockito-sample && git clone [email protected]:rogeriogentil/evosuite-junit-mockito-sample.git && cd evosuite-junit-mockito-sample && mvn evosuite:generate -Dcuts=rogeriogentil.service.AuthenticationImpl && mvn evosuite:export && mvn evosuite:prepare test

Current Result

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Executing org.evosuite.runtime.InitializingListener
WARN: scaffolding file not found. If this module has tests, recall to call the preparation step before executing the tests. For example, in Maven you need to make sure that 'evosuite:prepare' is called. See documentation at www.evosuite.org for further details.
Running rogeriogentil.service.AuthenticationImpl_ESTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.889 sec - in rogeriogentil.service.AuthenticationImpl_ESTest
Running rogeriogentil.service.AuthenticationImplTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.494 sec <<< FAILURE! - in rogeriogentil.service.AuthenticationImplTest
mustAuthenticate(rogeriogentil.service.AuthenticationImplTest)  Time elapsed: 0.494 sec  <<< ERROR!
org.mockito.exceptions.base.MockitoException: 
ClassCastException occurred while creating the mockito mock :
  class to mock : 'rogeriogentil.repository.Users', loaded by classloader : 'sun.misc.Launcher$AppClassLoader@7f31245a'
  created class : 'org.mockito.codegen.Users$MockitoMock$110167820', loaded by classloader : 'org.evosuite.runtime.instrumentation.EvoClassLoader@67117f44'
  proxy instance class : 'org.mockito.codegen.Users$MockitoMock$110167820', loaded by classloader : 'org.evosuite.runtime.instrumentation.EvoClassLoader@67117f44'
  instance creation by : ObjenesisInstantiator

You might experience classloading issues, please ask the mockito mailing-list.

	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:48)
	at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
	at org.mockito.Mockito.mock(Mockito.java:1907)
	at org.mockito.Mockito.mock(Mockito.java:1816)
	at rogeriogentil.service.AuthenticationImplTest.mustAuthenticate(AuthenticationImplTest.java:26)


Results :

Tests in error: 
  AuthenticationImplTest.mustAuthenticate:26 Mockito 
ClassCastException occurre...

Tests run: 4, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Expected result

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Executing org.evosuite.runtime.InitializingListener
Running rogeriogentil.service.AuthenticationImplTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.444 sec - in rogeriogentil.service.AuthenticationImplTest
Running rogeriogentil.service.AuthenticationImpl_ESTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.195 sec - in rogeriogentil.service.AuthenticationImpl_ESTest

Results :

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------------

Additional info

This behavior seems unstable. There are times when the error occurs and others do not.

  • Detail 1: The error never occurs on /tmp/ folder.

    • Stable: cd /tmp && rm -rf evosuite-junit-mockito-sample && git clone [email protected]:rogeriogentil/evosuite-junit-mockito-sample.git && cd evosuite-junit-mockito-sample && mvn evosuite:generate -Dcuts=rogeriogentil.service.AuthenticationImpl && mvn evosuite:export && mvn evosuite:prepare test
  • Detail 2: Sometimes new test suites are created, sometimes don't.

[INFO] WARN: failed to generate tests for rogeriogentil.service.AuthenticationImpl
  • Detail 3: The following message is logged even passing the option evosuite:prepare (file .scaffolding_list.tmp not always is generated):
WARN: scaffolding file not found. If this module has tests, recall to call the preparation step before executing the tests. For example, in Maven you need to make sure that 'evosuite:prepare' is called. See documentation at www.evosuite.org for further details.
@xingxinghuo1000
Copy link

xingxinghuo1000 commented Feb 13, 2020

Try execute this:

find ./ -name "*ESTest*.java" | xargs sed -i 's/separateClassLoader = true/separateClassLoader = false/g'

See this document: http://www.evosuite.org/documentation/measuring-code-coverage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants