我有一个项目,主要是Java (使用maven作为构建工具),我们正在寻找添加一些python模块。将代码放在src/main/python中很容易,但是我还没有找到一个很好的方法来将maven的测试框架集成到我们的python单元测试中。有没有好的方法可以让我的java单元测试和python单元测试以相同的maven目标运行?(如果python单元测试的结果将显示在站点报告中,则会加分)。
发布于 2011-02-03 10:34:27
这似乎就是你要找的。还有一些其他地方在讨论这个问题。
http://steveberczuk.blogspot.com/2009/12/continuous-integration-of-python-code.html
http://www.mojohaus.org/exec-maven-plugin/
发布于 2020-07-22 00:17:04
受http://steveberczuk.blogspot.com/2009/12/continuous-integration-of-python-code.html启发(正如@S.Lott所指出的),下面是一个有效的示例:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>python-test</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>python3</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>-m</argument>
<argument>unittest</argument>
<argument>discover</argument>
<argument>.</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>在这种情况下,我们的测试是在${project.build.directory}上进行的,并且构建机器上安装了python3。
发布于 2013-04-26 15:20:51
您还可以研究一下http://mavenjython.sourceforge.net/test/。尽管如此,Jython可能不支持在Python代码中使用的内容。
https://stackoverflow.com/questions/4881482
复制相似问题