IntelliJ IDEA에서 EvoSuite 실행(JUnit Test Generator)

Developer Tools|2017. 6. 28. 20:10

JUnit 테스트를 자동 생성해야 할 일이 생겼다. 이런건 뭔가 큰 잘못을 저지르는 기분이긴 하지만 어쩔 수 없는 상황이다.
구글링 하니 JUnit-Tools와 EvoSuite가 상단에 나왔다. JUnit-Tools는 훑어 봐도 명확히 어떤걸 어떻게 만들어 준다는 건지 감이 안와서 일단 EvoSuite를 선택했다.

http://www.evosuite.org/evosuite/

나는 IDEA를 사용하니 IDEA 플러그인(http://www.evosuite.org/documentation/intellij-idea-plugin/)을 Settings > Plugins에서 "EvoSuite Plugin"으로 검색해서 설치하고 재시작한다.

패키지 하나를 우클릭하고 Run EvoSuite를 선택하니 Maven과 Java 설치 경로를 지정하는 창이 나온다. OK 버튼을 눌러서 실행하면 된다(만약 OK 버튼이 안보이면 창 크기를 조정한다).

Going to execute command:
D:\dev\tool\apache-maven-3.3.9\bin\mvn.cmd  compile  evosuite:generate  -Dcores=1  -DmemoryInMB=2000  -DtimeInMinutesPerClass=3  -DspawnManagerPort=5617  -Dcuts=com.acme.spring.security.CustomAuthenticationFailureHandler,com.acme.spring.security.AuthJdbcDaoImpl,com.acme.spring.security.AuthManager,com.acme.spring.security.AuthUser  evosuite:export  -DtargetFolder=src/evo
in folder: G:\repos\my-project
Going to execute command:
D:\dev\tool\apache-maven-3.3.9\bin\mvn.cmd  compile  evosuite:generate  -Dcores=1  -DmemoryInMB=2000  -DtimeInMinutesPerClass=3  -DspawnManagerPort=5617  -Dcuts=com.acme.spring.security.CustomAuthenticationFailureHandler,com.acme.spring.security.AuthJdbcDaoImpl,com.acme.spring.security.AuthManager,com.acme.spring.security.AuthUser  evosuite:export  -DtargetFolder=src/evo
in folder: G:\repos\my-project
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for console:console:war:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 488, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Downloading: http://192.168.0.123:8081/artifactory/plugins-release/org/codehaus/mojo/maven-metadata.xml
Downloading: http://192.168.0.123:8081/artifactory/plugins-snapshot/org/codehaus/mojo/maven-metadata.xml
Downloading: http://192.168.0.123:8081/artifactory/plugins-snapshot/org/apache/maven/plugins/maven-metadata.xml
Downloading: http://192.168.0.123:8081/artifactory/plugins-release/org/apache/maven/plugins/maven-metadata.xml
Downloaded: http://192.168.0.123:8081/artifactory/plugins-snapshot/org/apache/maven/plugins/maven-metadata.xml (18 KB at 20.4 KB/sec)
Downloaded: http://192.168.0.123:8081/artifactory/plugins-snapshot/org/codehaus/mojo/maven-metadata.xml (27 KB at 29.4 KB/sec)
Downloaded: http://192.168.0.123:8081/artifactory/plugins-release/org/apache/maven/plugins/maven-metadata.xml (18 KB at 15.2 KB/sec)
Downloaded: http://192.168.0.123:8081/artifactory/plugins-release/org/codehaus/mojo/maven-metadata.xml (27 KB at 22.4 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.317 s
[INFO] Finished at: 2016-05-25T16:47:01+09:00
[INFO] Final Memory: 10M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'evosuite' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\daniel\.m2\repository), central (http://192.168.0.123:8081/artifactory/plugins-release), snapshots (http://192.168.0.123:8081/artifactory/plugins-snapshot)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

실행 결과 콘솔에 빌드 실패가 뜬다. IDEA 플러그인은 Maven에 의존하기 때문에, 결국 아래 페이지에 있는 모든 내용을 pom.xml에 적용한 후에야 오류 없이 테스트 코드 생성을 시작한다.

http://www.evosuite.org/documentation/maven-plugin/

기존 pom.xml과 diff 해보니 아래와 같은 코드를 추가했다.

    <properties>
        <evosuiteVersion>1.0.3</evosuiteVersion>
    </properties>

    <dependencies>
        <!-- Testing -->
        <dependency>
            <groupId>org.evosuite</groupId>
            <artifactId>evosuite-standalone-runtime</artifactId>
            <version>${evosuiteVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <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>
            <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>
        </plugins>
    </build>

// ... 중략

    <repositories>
        <repository>
            <id>EvoSuite</id>
            <name>EvoSuite Repository</name>
            <url>http://www.evosuite.org/m2</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>EvoSuite</id>
            <name>EvoSuite Repository</name>
            <url>http://www.evosuite.org/m2</url>
        </pluginRepository>
    </pluginRepositories>

Core 2개에 Core 당 2,000MB의 메모리를 부여하고, 클래스당 3분의 시간을 할당하도록 조건을 설정했다. 퇴근 전에 총 713개의 클래스에 대해서 테스트 케이스를 생성하도록 실행했는데 다음날 아침에 오니 생성이 끝나 있었다(로그에는 6시간 48분이 걸렸다고 찍혀있다).

전체 컴파일을 하니 없는 객체에 대해서 assertSame을 수행하는 오류와 테스트 코드에서 인수에 null을 넘기기 때문에 발생하는 메소드 ambiguous 문제가 여러 개 발생한다. 오류는 그냥 에러가 발생하는 코드를 삭제해서 해결했다.

전체 테스트를 Coverage 측정과 함께 실행하니 총 6150개의 테스트 중 23개가 실패한다. 실패한 테스트를 삭제하고 다시 실행하니 테스트 커버리지(라인)는 39.5%가 나온다.

단위 테스트가 전혀 작성되지 않은 소스 코드를 받아서 무조건 커버리지가 나오게 테스트를 만들어야 하는 상황이라서 EvoSuite를 사용했지만 기분은 별로다. 그냥 시간과 전기 낭비인 것 같아서 ...


EOF

댓글()