【发布时间】: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