Используйте платформу jenkins для запуска тестов спока в проекте maven - PullRequest
0 голосов
/ 28 января 2019

Я создал проект maven, который состоит из тестов junit и spock.Код обоих тестов.

public class AppTest 
{
    /**
     * Rigorous Test :-)
     */
    @Test
    public void shouldAnswerWithTrue()
    {
        assertTrue( true );
    }
}

class SpockTest extends Specification  {

    def "one plus one should equal two"() {
        expect:
        1 + 1 == 2
    }

}

На моем локальном компьютере, когда я запускаю mvn test, он обманывает оба тестовых класса.Я развернул проект в репозитории git и настроил jenkins для проекта maven.Я нажимаю на хранилище и выполняю задание для этого проекта, однако jenkins обнаруживает только класс AppTest для теста JUnit.Я изменил pom.xml и добавил файл regadring в https://github.com/menonvarun/testInProgress-spock-client.Структура моего проекта.

enter image description here

содержимое файла org.spockframework.runtime.extension.IGlobalExtension

org.imaginea.jenkins.testinprogress.spock.SpockTestInProgressExtension

pom.xml

<repositories>
    <repository>
      <id>repo.jenkins-ci.org</id>
      <url>http://repo.jenkins-ci.org/public/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.spockframework</groupId>
      <artifactId>spock-core</artifactId>
      <version>1.0-groovy-2.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.imaginea.jenkins.plugins</groupId>
      <artifactId>testInProgress-spock-client</artifactId>
      <version>0.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

Я установил на платформу jenkins testInProgress плагин.После этого я помещаю измененный проект maven в хранилище и снова выполняю задание для проекта maven.В другой раз Дженкинс не обнаружил класс SpockTest.В чем может быть проблема?

1 Ответ

0 голосов
/ 28 января 2019

Попробуйте поместить тесты спока в папку groovy:

  • src
    • test
      • groovy
        • com.jenk ...
          • SpockTest.groovy

Затем добавьте gmavenplus-plugin (Groovy компилятор) и maven-surefire-plugin (тестовый прогон) в pom.xml:

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.6.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
        </plugins>
    </pluginManagement>

    ...

    <plugins>
        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <configuration>
                <targetBytecode>1.8</targetBytecode>
                <warningLevel>2</warningLevel>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compileTests</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
        </plugin>
    </plugins>

Для отладки в Jenkins, чтобы убедиться, что ожидаемый тест запускается лучше, если условие не выполнено:

def "one plus one should equal two"() {
    expect:
    1 + 1 == 3
}
...