我有一个带有一些测试的LibGDX项目。结构如下:
当我从Eclipse运行测试时,它们全部变为绿色,但是每当我尝试从gradle命令行运行它们(./gradlew测试)时,assets文件夹都会出错。我相信这是因为测试不是从 Assets 文件夹启动的,而是从Eclipse启动的。
我怎么解决这个问题 ?有没有办法告诉gradle在运行测试时使用core / assets作为工作区目录?
这是我得到的错误:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: myasset.png
最佳答案
我找到了实现自己想要的方法。我在这里将解决方案发布给任何可能需要它的人。 gradle中有一个名为workingDir
的属性用于测试任务。所以我只需要将其设置在正确的文件夹中即可。在项目的build.gradle
文件(根文件夹)内,只需添加以下部分:
project(":core") {
apply plugin: "java"
// Add the following test section
test{
workingDir= new File("/assets")
}
// Rest of the file
}
而已!我的测试现在从命令行运行为绿色。
关于unit-testing - 找不到Gradle命令行 Assets 中的Libgdx测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47122554/