gpt4 book ai didi

java - 无法测试libgdx项目

转载 作者:行者123 更新时间:2023-12-03 06:21:59 24 4
gpt4 key购买 nike

我的项目团队忙于使用libgdx编写跨平台游戏。我正在尝试进行单元测试,目前我只是导入了类,这是我的代码:

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.mygdx.game.*;
import com.mygdx.game.input.TouchInputProcessor;


public class CarTest {

Car car;
World world;
Vector2 vector;

@Before
public void setUp() throws Exception {
vector = new Vector2(0.0f, 0.0f);
try {
this.world = new World(vector, true);

this.car = new Car(world, 2, 4, new Vector2(10, 10), (float) Math.PI,
60, 20, 60);
} catch (Exception e) {
e.getMessage();
}

}

[…]

}

并且在运行junit时出现以下错误:
java.lang.ExceptionInInitializerError
at CarTest.setUp(CarTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Unable to read file for extraction: gdx-box2d64.dll

如何使我的设置功能可以进行测试?或者更好的是,如何对libgdx项目进行单元测试?

最佳答案

在项目gradle脚本中通过testCompile添加依赖项。

testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"

关于java - 无法测试libgdx项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23541494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com