【问题标题】:unit testing libgdx with using gdx functionallity使用 gdx 功能对 libgdx 进行单元测试
【发布时间】:2019-08-23 15:09:17
【问题描述】:

我有一个正在运行的 libgdx 项目,我想对其进行单元测试。

我不知道如何在单元测试中使用 gdx 功能,我不喜欢模拟。我在单元测试中使用 libgdx 框架时遇到错误。

以下代码出现以下错误 (Texture texture = new Texture("ship.png");):

java.lang.NullPointerException
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:88)

代码:

public class MapDrawerTest extends ApplicationAdapter {

    MapDrawer mapDrawer;
    SpriteBatch batch;

    @Before
    public void setUp() throws Exception {

        Schiff schiff = new Schiff();
        World world = new World(100,100);
        mapDrawer = new MapDrawer(world, schiff);
        batch =  Mockito.mock(SpriteBatch.class);
    }

    @Test
    public void drawFeld() {

        Feld feld1 = new Feld(new Feldkoordinate(1,1), Feldtyp.LANDPALMEN);

        Texture texture = new Texture("ship.png");
        List<Texture> textures = new ArrayList<Texture>();
        textures.add(texture);
        feld1.addTexture(new FeldTexture(textures,60));

        mapDrawer.drawFeld(batch, feld1);

    }
}

【问题讨论】:

    标签: libgdx


    【解决方案1】:

    您需要将无头后端添加到您的依赖项并在您的单元测试运行之前对其进行初始化。

    This guide 解释了所有必要的步骤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-25
      • 2017-04-14
      • 1970-01-01
      • 2022-10-20
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多