EvoSuite / evosuite

EvoSuite - automated generation of JUnit test suites for Java classes
http://www.evosuite.org
GNU Lesser General Public License v3.0
841 stars 343 forks source link

Mocking static methods in collaborators of CUT #50

Open JavaJimFl opened 8 years ago

JavaJimFl commented 8 years ago

Good Afternoon,

I've run into an issue while trying to generate test cases for a class (let's call it MyClass) using the command line. The class relies heavily on collaborators that use static factory methods. Unit test generation failed with the following stack trace:

[MASTER] 15:49:11.591 [logback-2] ERROR ClientNodeImpl - Error when generating tests for: com.foo.Myclass with seed 1471549731211. Configuration id : null
java.lang.ExceptionInInitializerError: null
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_77]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_77]
    at org.evosuite.setup.TestClusterUtils.getClass(TestClusterUtils.java:330) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.io.output.OutputCoverageFactory.getCoverageGoals(OutputCoverageFactory.java:85) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.io.output.OutputCoverageSuiteFitness.determineCoverageGoals(OutputCoverageSuiteFitness.java:79) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.io.output.OutputCoverageSuiteFitness.<init>(OutputCoverageSuiteFitness.java:70) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.FitnessFunctions.getFitnessFunction(FitnessFunctions.java:125) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.strategy.TestGenerationStrategy.getFitnessFunctions(TestGenerationStrategy.java:87) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.strategy.WholeTestSuiteStrategy.generateTests(WholeTestSuiteStrategy.java:68) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.TestSuiteGenerator.generateTests(TestSuiteGenerator.java:616) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.TestSuiteGenerator.generateTestSuite(TestSuiteGenerator.java:193) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.rmi.service.ClientNodeImpl$1.run(ClientNodeImpl.java:145) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_77]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
Caused by: org.evosuite.runtime.mock.java.lang.MockRuntimeException: Application Context has not been initialized
    at com.foo.MyFactory.getContext(MyFactory.java:26) ~[classes/:na]
    at <evosuite>.<evosuite>(<evosuite>) ~[na:na]
    at <evosuite>.<evosuite>(<evosuite>) ~[na:na]

MyClass relies on a factory called MyFactory that in turn has a static method called getContext(). getContext() throws a RuntimeException when it hasn't been initialized, which is the case here. I think this problem may be caused by the call to getContext(), because it behaves as if it were not mocked. I noticed that Mockito classes are used for mocking, but as far as I know, the Mockito framework can't mock static methods or final classes. Another thing about this situation that's really interesting is the factory class is actually a transitive collaborator. The primary collaborator of the CUT is actually another class with static methods, and I think that would have been mocked instead.

I have three questions:

My environment:

My configuraton is a stock evosuite.properties file with the following changes: use_separate_classloader=false (JMockit and JaCoCo are used by the project) junit_suffix=EsTest show_progress=false

Thanks for tackling such a difficult problem!

arcuri82 commented 8 years ago

Hi,

it does not (and will not) mock static methods, but it can mock final classes (as long as they are not loaded by the bootstrap classloader, eg "java.*"). Mocking static methods would have far too many negative consequences / complications for automated test generation

Nope :) there would be no advantage (EvoSuite strip out the "final" when loading classes, so Mockito can still be used on those types of classes)

unfortunately no :(

From you description/logs, it looks like class loading fails due to wrong static state in other classes (ie, exception during static initializer). This is a very special case, which so far I have seen it only once in my whole career :( Handling it in EvoSuite (or any other test generation tool) would be very complicated (ie, set static state of JVM in the right way even before some classes are loaded).

Unless more people will have the same kind of issue, unfortunately there would not be much ROI in trying to handle it now :(

cheers

JavaJimFl commented 8 years ago

Hi,

I agree, the factory class could have been coded better, (i.e., lazily initialize the context instead of throwing an exception), but my initial goal was to apply EvoSuite to the AUT "as-is".

That said, I did change the AUT code to lazily initialize the Spring context from the classpath instead of failing as it does now. Using the same configuration evosuite-master-1.0.4 above

[MASTER] 09:12:07.222 [logback-2] ERROR ClientNodeImpl - Error when generating tests for: com.foo.MyClass with seed 1471871486216. Configuration id : null
java.lang.ExceptionInInitializerError: null
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_77]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_77]
    at org.evosuite.setup.TestClusterUtils.getClass(TestClusterUtils.java:330) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.io.output.OutputCoverageFactory.getCoverageGoals(OutputCoverageFactory.java:85) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.io.output.OutputCoverageSuiteFitness.determineCoverageGoals(OutputCoverageSuiteFitness.java:79) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.io.output.OutputCoverageSuiteFitness.<init>(OutputCoverageSuiteFitness.java:70) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.coverage.FitnessFunctions.getFitnessFunction(FitnessFunctions.java:125) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.strategy.TestGenerationStrategy.getFitnessFunctions(TestGenerationStrategy.java:87) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.strategy.WholeTestSuiteStrategy.generateTests(WholeTestSuiteStrategy.java:68) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.TestSuiteGenerator.generateTests(TestSuiteGenerator.java:616) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.TestSuiteGenerator.generateTestSuite(TestSuiteGenerator.java:193) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at org.evosuite.rmi.service.ClientNodeImpl$1.run(ClientNodeImpl.java:145) ~[evosuite-master-1.0.4-alpha2.jar:1.0.4-alpha2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_77]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [com/foo/my-Context.xml]; nested exception is org.evosuite.runtime.mock.java.lang.MockThrowable: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at <evosuite>.<evosuite>(<evosuite>) ~[na:na]
    at <evosuite>.<evosuite>(<evosuite>) ~[na:na]
Caused by: org.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface
    at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:128) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    ... 2 common frames omitted
[Loaded sun.net.ConnectionResetException from C:\Program Files\Java\jdk1.8.0_77\jre\lib\rt.jar]
* Computation finished

This error about is usually caused by the presence of two different Spring context JARs in the classpath. Since I created the classpath, I checked it and confirmed it contains only one copy of the Spring Context JAR. I added the -verbose JVM arg to verify from which Spring JAR was the context classes were loaded b EvoSuite, but I didn't see anything related to Spring at all.

Another possible explanation for this issue appears to involve one classloader loading the org.springframework.context.config.ContextNamespaceHandler class and another the org.springframework.beans.factory.xml.NamespaceHandler class. I'm not sure how to verify that.

Since I'm kind of stuck using 1.0.4-alpha2, I switched to 1.0.3, and received a different error:

* Error while initializing target class: java.lang.ExceptionInInitializerError
[MASTER] 09:52:40.250 [logback-2] ERROR TestSuiteGenerator - Problem for com.foo.MyClass Full stack:
java.lang.ExceptionInInitializerError: null
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_77]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_77]
    at org.evosuite.Properties.getTargetClass(Properties.java:2339) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.Properties.getTargetClass(Properties.java:2304) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.TestClusterGenerator.initializeTargetMethods(TestClusterGenerator.java:363) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.TestClusterGenerator.generateCluster(TestClusterGenerator.java:135) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.DependencyAnalysis.analyze(DependencyAnalysis.java:117) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.DependencyAnalysis.analyzeClass(DependencyAnalysis.java:131) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.TestSuiteGenerator.generateTestSuite(TestSuiteGenerator.java:110) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.rmi.service.ClientNodeImpl$1.run(ClientNodeImpl.java:145) [evosuite-1.0.3.jar:1.0.3]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_77]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client1BatchTransactionTemplate' defined in class path resource [com/foo/client1-Context.xml]: Cannot resolve reference to bean 'client1TxManager' while setting constructor argument; nested exception is org.evosuite.runtime.mock.java.lang.MockThrowable: Error creating bean with name 'client1TxManager' defined in class path resource [com/foo/client1-Context.xml]: Cannot resolve reference to bean 'client1SessionFactory' while setting bean property 'sessionFactory'
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[na:na]
    at <evosuite>.<evosuite>(<evosuite>) ~[na:na]
    at <evosuite>.<evosuite>(<evosuite>) ~[na:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client1TxManager' defined in class path resource [com/foo/client1-Context.xml]: Cannot resolve reference to bean 'client1SessionFactory' while setting bean property 'sessionFactory'; nested exception is org.evosuite.runtime.mock.java.lang.MockThrowable: Error creating bean with name 'client1SessionFactory' defined in class path resource [com/foo/client1-Context.xml]: Invocation of init method failed
    ... 3 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client1SessionFactory' defined in class path resource [com/foo/client1-Context.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.evosuite.runtime.mock.java.lang.MockThrowable cannot be cast to oracle.net.ns.NetException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[na:na]
    ... 2 common frames omitted
Caused by: java.lang.ClassCastException: org.evosuite.runtime.mock.java.lang.MockThrowable cannot be cast to oracle.net.ns.NetException
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:439) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:454) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:693) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:251) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528) ~[ojdbc6-11.2.0.4.0.jar:11.2.0.3.0]
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) ~[commons-dbcp-1.4.jar:1.4]
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) ~[commons-dbcp-1.4.jar:1.4]
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556) ~[commons-dbcp-1.4.jar:1.4]
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545) ~[commons-dbcp-1.4.jar:1.4]
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) ~[commons-dbcp-1.4.jar:1.4]
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) ~[commons-dbcp-1.4.jar:1.4]
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372) ~[spring-orm-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454) ~[spring-orm-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439) ~[spring-orm-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$6.run(AbstractAutowireCapableBeanFactory.java:1627) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_77]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1624) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[na:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[na:na]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[na:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[na:na]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[na:na]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[na:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at com.foo.MyFactory.initApplicationContext(MyFactory.java:15) ~[classes/:na]
    at com.foo.MyFactory.getContext(MyFactory.java:28) ~[classes/:na]
    at com.foo.AnotherFactory.getBean(AnotherFactory.java:71) ~[classes/:na]
    at com.foo.AnotherFactory.getBarRepository(AnotherFactory.java:382) ~[classes/:na]
    at com.foo.MyAbstractClass.<clinit>(MyAbstractClass.java) ~[classes/:na]
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_77]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_77]
    at org.evosuite.Properties.getTargetClass(Properties.java:2339) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.Properties.getTargetClass(Properties.java:2304) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.TestClusterGenerator.initializeTargetMethods(TestClusterGenerator.java:363) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.TestClusterGenerator.generateCluster(TestClusterGenerator.java:135) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.DependencyAnalysis.analyze(DependencyAnalysis.java:117) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.setup.DependencyAnalysis.analyzeClass(DependencyAnalysis.java:131) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.TestSuiteGenerator.generateTestSuite(TestSuiteGenerator.java:110) ~[evosuite-1.0.3.jar:1.0.3]
    at org.evosuite.rmi.service.ClientNodeImpl$1.run(ClientNodeImpl.java:145) [evosuite-1.0.3.jar:1.0.3]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_77]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
* Computation finished

It seems v1.0.3 can load the main Spring application context from the classpath, but it has issues finding linked context files, e.g, <import resource="client1-Context.xml" /> (which is actually located at com/foo/client1-Context.xml).

I just wanted to share what I found. I understand that mocking static calls isn't on your roadmap, so I'll focus my efforts on generating unit tests for classes without such dependencies. Thanks again for all your hard work, and if there's anything I can do to help with this feature request, please let me know.

arcuri82 commented 8 years ago

Hi, thx for reporting this issue. At a first look, it does seem like a classloader issue. And, if that is indeed the case, it would mean a bug in EvoSuite. But it is hard to debug it with just that log :( If you are working on a open source system (eg on Github), can you point us to it, so we can try to reproduce the problem? if it is not open-source, can you write a small project to reproduce this issue?

cheers

JavaJimFl commented 8 years ago

Hi,

It's not an open source project, but I can try to cook up something that replicates the same symptoms in the next couple of days. I take it I can email you a small Maven project containing the example code?

Thanks,

Jim

arcuri82 commented 8 years ago

Hi, a small Maven project would be perfect ;) but instead of email, it would be best if you zip it and then upload it here as an attachment (so easier to do not forget about it, as i m not sure when i ll have time to look into it)

cheers

JavaJimFl commented 7 years ago

After using EvoSuite for awhile, I can see this particular test actually pointed out a bug in the application, so I don't want you all to waste your time working this issue as some type of bug fix.

That said, the legacy application I'm working with has a lot of static calls that in turn wrap database queries, or in the case of this issue, the loading of a large Spring application context. The generated tests involving these classes resemble integration tests more than unit tests. I'm not sure how to proceed in these situations.

Once again, thanks for creating this project. Even though I've submitted quite a few potential issues lately, the tests EvoSuite has generated for one of our application modules represent man-years of labor had they been written by hand.