Maven在构建期间运行Angular测试

时间:2020-01-06 09:42:12

标签: angular spring maven testing

我有一个基于Maven的项目,后端有Spring,前端有Angular 8,我想在构建过程中自动运行Angular单元测试。

我已经阅读到通常使用PhantomJS,但是不再对其进行维护,因此,我希望看到一个完整的,即使是基本示例的应用程序示例,该示例也可以在构建过程中运行Angular测试。

我还读到有可用的无头铬,但我不清楚如何连接东西以进行测试。

有人可以给我提供一个例子吗?

2 个答案:

答案 0 :(得分:0)

要运行角度单位测试,应运行:

ng test

它将自动下载您需要的工具(包括无头chrome)。可以在这里找到更多信息:https://angular.io/guide/testing

如果必须从maven运行此程序,则可以使用

exec-maven-plugin

例如参见:I want to execute shell commands from Maven's pom.xml

但是您最好将前端和后端构建分开,并将它们视为独立的工件。

答案 1 :(得分:0)

这就是我要做的:

<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.3.2</version>
                <executions>
                    <execution>
                        <id>karma</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <executable>npm</executable>
                            <arguments>
                                <argument>test</argument>
                                <argument>--</argument>
                                <argument>--watch=false</argument>
                            </arguments>
                            <skip>${skipTests}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
相关问题