통합 테스트를 위해 병렬 메이븐 테스트 실행을 생각해 보려고합니다.Maven surefire 플러그인, 빌드 수명주기 동안 시스템 속성 설정 및 가져 오기
테스트 실행을 시작하기 전에 sql-maven-plugin을 사용하여 테스트 실행을 시작하기 전에 maven surefire 플러그인 매개 변수 및 병렬 실행과 함께 시작하는 것이 좋습니다.
내가 이해하지 못하는 이유는 surefire 플러그인이 설정하는 시스템 등록 정보를 사용하는 방법입니다. sql-maven-plugin (또는 해당 플러그인에 대한 다른 플러그인)을 사용하십시오. 이 설치가 실패합니다.
확실한 플러그인 구성 :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<databaseSchema>test_schema_${surefire.forkNumber}</databaseSchema>
</systemPropertyVariables>
</configuration>
</plugin>
SQL-받는다는 - 플러그인 구성 :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<username>user_with_create_privs</username>
<password>password</password>
<url>jdbc:mysql://localhost/dummy_schema</url>
</configuration>
<executions>
<execution>
<id>create-db</id>
<phase>process-test-classes</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:mysql://localhost/dummy_schema</url>
<autocommit>true</autocommit>
<sqlCommand>create database ${databaseSchema}</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
쉘 실행 :
mvn test
,
결과 출력 :
[DEBUG] SQL: drop database ${databaseSchema}
[ERROR] Failed to execute: drop database ${databaseSchema}
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute
(create-db) on project billing-core: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '{databaseSchema}' at line 1 -> [Help 1]
그래서, $처럼 보인다는 {databaseSchema}을 채워, 또는 구문 문제가되지 않습니다. 나는 손을 대봤지만 쉽지 않은 것처럼 보이지만이 작업을 할 수는 없습니다.
, 당신은 메이븐 안전 장치 플러그인을 살펴 있어야합니다. –
Surefire의'systemPropertyVariables'는 테스트를 실행하는 JVM을 생성 할 때 시스템 속성을 설정합니다. 분명히 Maven이 sql-maven-plugin을 실행하려 할 때, 그 속성은 Maven 프로젝트를 위해 설정된 속성이 아니다. – Tome
@ 토미 그래서 기본적으로 sql-maven-plugin과 surefire 플러그인은 내가 원하는 방식으로 호환되지 않습니까? – Wrench