使用PlayN框架,如何在项目中包含单元测试? [英] With PlayN framework, how can I include unit tests in my project?

查看:86
本文介绍了使用PlayN框架,如何在项目中包含单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我一直在维护第二个沙箱项目,在其中测试概念并通过障碍进行工作.但这并不是很有效,因为我最终不得不重复很多代码,并且无法为我的游戏维持一套持久的回归测试.

Right now I've been maintaining a second sandbox project where I test concepts and work through roadblocks. But this is not very efficient as I end up having to duplicate a lot of code and am unable to maintain a durable set of regression tests for my game.

我的项目中确实有一个单元测试文件夹,但是无法测试框架本身的组件,因为它们依赖于平台特定的实现,而这些实现对于进行开发的核心分支是不可用的.

I do have a folder of unit tests within my project, but it is impossible to test components of the framework itself as they depend on platform-specific implementations that are not available to the core branch where development takes place.

我已找到PlayN框架的

I have located the PlayN framework's set of tests. Is it possible to leverage these for testing one's own project? Is it possible to include two Game classes within one project?

我在此处提出了这个问题,但是从来没有得到满意的答复.

I see this question was raised here, but it never really got a satisfactory response.

推荐答案

您无法轻松编写针对PlayN支持的不同后端运行的单元测试.显然,在Android手机或iOS设备上自动运行单元测试将是一个很大的挑战.但是,您可以轻松编写针对Java后端运行的单元测试.

You cannot easily write unit tests that are run against the different backends supported by PlayN. Clearly it would be quite a challenge to automatically run your unit tests on an Android phone or iOS device. However, you can write unit tests that run against the Java backend pretty easily.

通常,我对项目进行结构设计,以使我的核心子模块对play n-java具有test依赖性,然后使用playn-java后端运行单元测试.我发现它可以很好地工作,尽管我通常不测试直接与PlayN交互的内容,因为很难对可视化代码进行单元测试.我进行单元测试的东西很少打PlayN电话.

I generally structure my projects such that my core submodule has a test dependency on play n-java and then I run my unit tests using the playn-java backend. I have found this to work reasonably well, though I don't usually test much that directly interacts with PlayN because it's hard to unit test visual code. The things I unit test rarely make PlayN calls.

您还可以针对HTML5后端进行单元测试,但这确实很慢.查看 HTMLUnit .

You can also unit test against the HTML5 backend, but it's reaaaaally slow. Look at HTMLUnit.

将playn-java作为测试依赖项添加到您的core/pom.xml中:

Add playn-java to your core/pom.xml as a test dependency:

 <dependency>
   <groupId>com.googlecode.playn</groupId>
   <artifactId>playn-java</artifactId>
   <version>${playn.version}</version>
   <scope>test</scope>
 </dependency>

也将其添加到您的core/pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>com.googlecode.mavennatives</groupId>
      <artifactId>maven-nativedependencies-plugin</artifactId>
      <version>0.0.6</version>
      <executions>
        <execution>
          <id>unpacknatives</id>
          <phase>generate-resources</phase>
          <goals> <goal>copy</goal> </goals>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.12</version>
      <configuration>
        <argLine>-Djava.library.path=${basedir}/target/natives</argLine>
      </configuration>
    </plugin>
  </plugins>
</build>

这将在运行单元测试时正确设置LWJGL.

which will properly set up LWJGL when running your unit tests.

然后将其添加到您的单元测试中:

Then add this to your unit test:

 static {
     JavaPlatform.register();
 }

现在,您可以在单元测试中访问PlayN.foo()服务,它们甚至可以使用.

Now you can access PlayN.foo() services in your unit tests and they'll even work.

您可以像这样从Maven编译并运行测试:

You compile and run your tests from Maven like so:

mvn test

如果您需要在(Unix)构建服务器上运行单元测试,则需要确保构建服务器上安装了无头X Windows安装以及Mesa GL库.

If you need to run your unit tests on a (Unix) build server, you'll need to ensure that the build server has a headless X windows installation installed along with the Mesa GL libraries.

这篇关于使用PlayN框架,如何在项目中包含单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆