Тесты Спока безуспешны после запуска Maven - PullRequest
1 голос
/ 28 апреля 2019

Тесты успешно выполняются при автономном запуске (в IDE), но выдают: groovy.lang.MissingPropertyException при запуске через Maven

Я отладил mvn test и обнаружил, что gameObject не имеет полей, определенных во время выполнения при запуске черезMaven.Конкретное сообщение об исключении:

groovy.lang.MissingPropertyException: No such property: gameObject for class: org.monterinio.games.asteroids.player.view.PlayerView

Тестовая папка: src/test/groovy

Содержит (среди прочих) org.monterinio.games.asteroids.player.controller.action.BasicActionHandlerTest

Папка Src: src/main/java

Содержит (среди прочих):

package org.monterinio.games.asteroids.player.view;

public class PlayerView extends GameObjectView {

  public Player player;

  public PlayerView(Node view, Player gameObject) {
      super(view);
      this.player = gameObject;
  }
}


package org.monterinio.games.asteroids.player.model;

public class Player extends GameObject {

  private String name;
  private double angle;
  private List<Bullet> bullets;
  private AbstractMovementSignals movementSignals;
  private AbstractRotationSignals rotationSignals;
  private AbstractActionSignals actionSignals;

  public Player(String name) {
    this.name = name;
    this.movementSignals = new BasicMovementSignals();
    this.rotationSignals = new BasicRotationSignals();
    this.actionSignals = new BasicActionSignals();
    this.bullets = new ArrayList<>();
  }
}

Мой текущий pom.xml:

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.airhacks</groupId>
        <artifactId>afterburner.fx</artifactId>
        <version>1.7.0</version>
    </dependency>
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
    </dependency>

    <!-- TEST -->
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.3-groovy-2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testfx</groupId>
        <artifactId>testfx-core</artifactId>
        <version>4.0.15-alpha</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testfx</groupId>
        <artifactId>testfx-spock</artifactId>
        <version>4.0.15-alpha</version>
        <scope>test</scope>
    </dependency>
    <!-- FOR MOCKING IN SPOCK -->
    <dependency>
        <groupId>net.bytebuddy</groupId>
        <artifactId>byte-buddy</artifactId>
        <version>1.9.12</version>
    </dependency>
</dependencies>

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>dashboard.fxml</include>
                <include>dashboard.css</include>
            </includes>
            <targetPath>org/monterinio/games/asteroids</targetPath>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M3</version>
            <configuration>
                <testSourceDirectory>src/test/groovy</testSourceDirectory>
                <includes>
                    <include>**/*Spec.java</include>
                    <!-- Yes, .java extension -->
                    <include>**/*Test.java</include>
                    <!-- Just in case having "normal" JUnit tests -->
                </includes>
                <argLine>--illegal-access=deny</argLine>
                <argLine>--add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED</argLine>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>${gmaven-plugin.version}</version>
            <executions>
                <execution>
                    <!-- Without joint compilation - no dependencies between Java and Groovy (inheritance)-->
                    <goals>
                        <goal>addTestSources</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>${groovy.version}</version>
                    <type>pom</type>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>org.monterinio.games.asteroids.MainAsteroids</mainClass>
            </configuration>
        </plugin>
    </plugins>

Я ожидаю, что тесты пройдут успешно при выполнении Maven.

1 Ответ

0 голосов
/ 06 мая 2019

Открытие проверяемых пакетов решило проблему:

package.info

...
// needs to be opened for testing
opens org.monterinio.games.asteroids.player.model;
opens org.monterinio.games.asteroids.player.model.rotation;
...

Или просто открыв весь модуль:

open module asteroids {
  ...
}
...