EvoSuite / evosuite

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

ERROR TestSuiteGenerator - Full stack: java.lang.IllegalArgumentException: null #334

Closed pablovalle closed 3 years ago

pablovalle commented 3 years ago

Context

Hi, I am trying to generate Junit test cases to test an application done in Java, using Springboot and Hybernate. I am using maven to run evosuite because i want to integrate it in my Continuous Integration system (using Jenkins).

Steps to Reproduce

I have build the pom.xml as it appears here: [https://www.evosuite.org/documentation/maven-plugin/]()

EvoSuite Arguments

I am triyng the following command: mvn compile evosuite:generate

Current Result

The result i get is the following one:

[INFO] === CTG run results === [INFO] Removed test suites: 0 [INFO] New test suites: 0 [INFO] Missing classes: [INFO] com.mufit.pum.web.UserRegistrationController [INFO] com.mufit.pum.config.SecurityConfig [INFO] com.mufit.pum.PumGameApplication [INFO] com.mufit.pum.config.LocaleConfig [INFO] com.mufit.pum.util.PasswordGenerator [INFO] com.mufit.pum.web.dto.UserRegistrationDto [INFO] com.mufit.pum.service.UserServiceImplementation [INFO] com.mufit.pum.web.MainController [INFO] com.mufit.pum.service.UserSecurityService [INFO] WARN: failed to generate tests for 9 classes out of 9 [INFO] Stopping spawn process manager [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:53 min [INFO] Finished at: 2020-12-16T14:06:42+01:00 [INFO] ------------------------------------------------------------------------

The log file says this:

[MASTER] 14:05:30.559 [pool-2-thread-1] ERROR TestSuiteGenerator - Problem for com.mufit.pum.config.SecurityConfig. Full stack: java.lang.IllegalArgumentException: null at org.evosuite.shaded.org.objectweb.asm.ClassReader.(ClassReader.java:160) at org.evosuite.shaded.org.objectweb.asm.ClassReader.(ClassReader.java:143) at org.evosuite.shaded.org.objectweb.asm.ClassReader.(ClassReader.java:418) at org.evosuite.setup.InheritanceTreeGenerator.analyzeClassStream(InheritanceTreeGenerator.java:238) at org.evosuite.setup.InheritanceTreeGenerator.createFromClassPath(InheritanceTreeGenerator.java:101) at org.evosuite.setup.DependencyAnalysis.initInheritanceTree(DependencyAnalysis.java:77) at org.evosuite.setup.DependencyAnalysis.analyzeClass(DependencyAnalysis.java:131) at org.evosuite.TestSuiteGenerator.initializeTargetClass(TestSuiteGenerator.java:110) at org.evosuite.TestSuiteGenerator.generateTestSuite(TestSuiteGenerator.java:130) at org.evosuite.rmi.service.ClientNodeImpl$1.run(ClientNodeImpl.java:145) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

Expected result

The expected result will be the Junit Test-cases build but i have no one.

Additional info

I am using this: mvn --version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: C:\apache-maven-3.6.3\bin.. Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_221\jre Default locale: es_ES, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

The code of my pom.xml file is the following one:

<properties>
    <java.version>1.8</java.version>
    <evosuiteVersion>1.0.6</evosuiteVersion>
</properties>

<dependencies>
    <dependency>
        <groupId>org.evosuite</groupId>
        <artifactId>evosuite-standalone-runtime</artifactId>
        <version>${evosuiteVersion}</version>
        <scope>test</scope>
      </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity5</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
      </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>       
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
           <executions>
             <execution>
               <id>add-test-source</id>
               <phase>generate-test-sources</phase>
               <goals>
                 <goal>add-test-source</goal>
               </goals>
               <configuration>
                  <sources>
                    <source>.evosuite/evosuite-tests</source>
                  </sources>
               </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
              <properties>
                <property>
                   <name>listener</name>
                   <value>org.evosuite.runtime.InitializingListener</value>
               </property>
              </properties>
           </configuration>
         </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.evosuite.plugins</groupId>
            <artifactId>evosuite-maven-plugin</artifactId>
            <version>${evosuiteVersion}</version>
            <executions><execution>
               <goals> <goal> prepare </goal> </goals>
               <phase> process-test-classes </phase>
            </execution></executions>
        </plugin>
    </plugins>

</build>

Many Thanks! Pablo.

jose commented 3 years ago

Hi @pablovalle,

Any chance you can try the latest version of EvoSuite? As the latest version has not been uploaded to the mvnrepository yet, you should first execute the following steps:

git clone https://github.com/EvoSuite/evosuite.git
cd evosuite
mvn install -DskipTests=true

and only then modify the following line in your project's pom.xml file from

<evosuiteVersion>1.0.6</evosuiteVersion>

to

<evosuiteVersion>1.1.1-SNAPSHOT</evosuiteVersion>

You can then re-execute the mvn compile evosuite:generate command.

-- Best, Jose

pablovalle commented 3 years ago

Hi @jose,

First of all thank you for your attention.

After having followed your indications I have been able to execute the mvn compile evosuit:generate command, and the proccess starts well but it gets blocked when the first job starts. It says that it will finish in 10 minutes (555 seconds) but it doesn't finish. I have left it and it says that the job has not finished in time... Ihave tried more than once getting the same output.

Here you have what it says:

mvn compile evosuite:generate [INFO] Scanning for projects... [INFO] [INFO] ---------------------------< com.mufit:pum >---------------------------- [INFO] Building PumGame 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ pum --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 20 resources [INFO] The encoding used to copy filtered properties files have not been set. This means that the same encoding will be used to copy filtered properties files as when copying other filtered resources. This might not be what you want! Run your build with --debug to see which files might be affected. Read more at https://maven.apache.org/plugins/maven-resources-plugin/examples/filtering-properties-files.html [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ pum --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] >>> evosuite-maven-plugin:1.1.1-SNAPSHOT:generate (default-cli) > compile @ pum >>> [INFO] [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ pum --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 20 resources [INFO] The encoding used to copy filtered properties files have not been set. This means that the same encoding will be used to copy filtered properties files as when copying other filtered resources. This might not be what you want! Run your build with --debug to see which files might be affected. Read more at https://maven.apache.org/plugins/maven-resources-plugin/examples/filtering-properties-files.html [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ pum --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] <<< evosuite-maven-plugin:1.1.1-SNAPSHOT:generate (default-cli) < compile @ pum <<< [INFO] [INFO] [INFO] --- evosuite-maven-plugin:1.1.1-SNAPSHOT:generate (default-cli) @ pum --- [INFO] Going to generate tests with EvoSuite [INFO] Total memory: 800mb [INFO] Time per class: 2 minutes [INFO] Number of used cores: 1 [INFO] Target: C:\Users\pablo\OneDrive\Escritorio\3curso\Web\PBL_froga\pum-game-repository\target\classes [INFO] Basedir: C:\Users\pablo\OneDrive\Escritorio\3curso\Web\PBL_froga\pum-game-repository [INFO] Started spawn process manager on port 58100 [INFO] EvoSuite 1.1.1-SNAPSHOT [INFO] Registered remote process from /127.0.0.1:58102 [INFO] Going to execute 11 jobs [INFO] Estimated completion time: 22 minutes, by 2020-12-16T21:22:11.609 [INFO] Going to start job for: com.mufit.pum.web.UserRegistrationController. Expected to end in 555 seconds, by 2020-12-16T21:09:26.875 [INFO] [MASTER] 21:23:11.595 [main] ERROR JobExecutor - The jobs did not finish in time [INFO] Updating database to com.mufit.pum.web.UserRegistrationController [INFO] Updating database to com.mufit.pum.model.Role [INFO] Updating database to com.mufit.pum.config.SecurityConfig [INFO] Updating database to com.mufit.pum.PumGameApplication [INFO] Updating database to com.mufit.pum.config.LocaleConfig [INFO] Updating database to com.mufit.pum.util.PasswordGenerator [INFO] Updating database to com.mufit.pum.model.User [INFO] Updating database to com.mufit.pum.web.dto.UserRegistrationDto [INFO] Updating database to com.mufit.pum.service.UserServiceImplementation [INFO] Updating database to com.mufit.pum.web.MainController [INFO] Updating database to com.mufit.pum.service.UserSecurityService [INFO] === CTG run results === [INFO] Removed test suites: 0 [INFO] New test suites: 0 [INFO] Missing classes: [INFO] com.mufit.pum.web.UserRegistrationController [INFO] com.mufit.pum.model.Role [INFO] com.mufit.pum.config.SecurityConfig [INFO] com.mufit.pum.PumGameApplication [INFO] com.mufit.pum.config.LocaleConfig [INFO] com.mufit.pum.util.PasswordGenerator [INFO] com.mufit.pum.model.User [INFO] com.mufit.pum.web.dto.UserRegistrationDto [INFO] com.mufit.pum.service.UserServiceImplementation [INFO] com.mufit.pum.web.MainController [INFO] com.mufit.pum.service.UserSecurityService [INFO] WARN: failed to generate tests for 11 classes out of 11 [INFO] Stopping spawn process manager [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 23:06 min [INFO] Finished at: 2020-12-16T21:23:12+01:00 [INFO] ------------------------------------------------------------------------

Best regards, Pablo.

pablovalle commented 3 years ago

Hi @jose,

Trying to understand where does evosuite block, we have found the following problem:

"Could not run phased build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.3-bin.zip'.\r\nCould not create an instance of type org.gradle.invocation.DefaultGradle.\r\nCould not configure services using GradleScopeCompileServices.configure().\r\nclass jdk.internal.loader.ClassLoaders$PlatformClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$PlatformClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')",

This problem is in evosuite folder so we don't know why could happen this.

Many thanks, Pablo.

jose commented 3 years ago

"Could not run phased build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.3-bin.zip'.\r\nCould not create an instance of type org.gradle.invocation.DefaultGradle.\r\nCould not configure services using GradleScopeCompileServices.configure().\r\nclass jdk.internal.loader.ClassLoaders$PlatformClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$PlatformClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')",

I'm afraid I can't understand that message. Isn't your project a maven-based project?

Any chance you can try to generate tests for a single class using EvoSuite's command line rather than EvoSuite's mvn plugin? I.e., in your project's directory run the following commands:

# Download project's deps
mvn dependency:go-offline -Dmaven.repo.local=deps

# Run EvoSuite on `com.mufit.pum.web.UserRegistrationController`
java -jar ___path_to_evosuite_repo_dir__\master\target\evosuite-master-1.1.1-SNAPSHOT.jar -class com.mufit.pum.web.UserRegistrationController -projectCP target\classes:deps
pablovalle commented 3 years ago

Okey, i will do it one by one this way it works.

Thank you!

qfzjava commented 3 years ago

bro, I got the same problem with u, I have saw the answer up there. but i don't know how to run the command:

Download project's deps

mvn dependency:go-offline -Dmaven.repo.local=deps

Run EvoSuite on com.mufit.pum.web.UserRegistrationController

java -jar _path_to_evosuite_repo_dir\master\target\evosuite-master-1.1.1-SNAPSHOT.jar -class com.mufit.pum.web.UserRegistrationController -projectCP target\classes:deps

can u teach me how to run the command... thank u!!!!!

qfzjava commented 3 years ago

this is my error:

Unknown lifecycle phase ".repo.local=deps". You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

pablovalle commented 3 years ago

Hi,

Just run the command: java -jar "path to evosuite dir repo"\master\target\evosuite-master-1.1.1-SNAPSHOT.jar -class "class you want to generate tests" -projectCP target\classes:deps