Added tests for Travis to fail if the jsons don't parse or something

This commit is contained in:
Yair Morgenstern 2019-11-10 21:39:10 +02:00
parent 91eed3fc02
commit 2df7bcafbd
7 changed files with 227 additions and 2 deletions

1
.gitignore vendored
View File

@ -135,3 +135,4 @@ android/release/android.aab
android/assets/maps/
android/release/android.aab.sig
android/release/android-release.aab
tests/build/

View File

@ -128,8 +128,46 @@ project(":core") {
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
// Taken from https://github.com/TomGrill/gdx-testing
project(":tests") {
apply plugin: "java"
test{
workingDir= file("../android/assets")
}
sourceSets.test.java.srcDirs = ["src/"]
dependencies {
/**
* If you do have some classes to test in os specific code you may want to uncomment
* some of these lines.
*
* BUT: I recommend to create seperate test sub projects for each platform. Trust me :)
*
*/
compile project(":core")
compile "junit:junit:4.12"
compile "org.mockito:mockito-all:1.9.5"
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-all:1.9.5"
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}}
tasks.eclipse.doLast {
delete ".project"
}

View File

@ -1 +1 @@
include 'desktop', 'android', 'ios', 'html', 'core'
include 'desktop', 'android', 'ios', 'html', 'core', 'tests'

22
tests/build.gradle Normal file
View File

@ -0,0 +1,22 @@
apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets {
test {
java {
srcDir 'src'
}
}
}
eclipse.project {
name = appName + "-tests"
}

View File

@ -0,0 +1,104 @@
/*******************************************************************************
* Copyright 2015 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package de.tomgrill.gdxtesting;
import java.util.HashMap;
import java.util.Map;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import static org.mockito.Mockito.mock;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.headless.HeadlessApplication;
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
public class GdxTestRunner extends BlockJUnit4ClassRunner implements ApplicationListener {
private Map<FrameworkMethod, RunNotifier> invokeInRender = new HashMap<FrameworkMethod, RunNotifier>();
public GdxTestRunner(Class<?> klass) throws InitializationError {
super(klass);
HeadlessApplicationConfiguration conf = new HeadlessApplicationConfiguration();
new HeadlessApplication(this, conf);
Gdx.gl = mock(GL20.class);
}
@Override
public void create() {
}
@Override
public void resume() {
}
@Override
public void render() {
synchronized (invokeInRender) {
for (Map.Entry<FrameworkMethod, RunNotifier> each : invokeInRender.entrySet()) {
super.runChild(each.getKey(), each.getValue());
}
invokeInRender.clear();
}
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void dispose() {
}
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
synchronized (invokeInRender) {
// add for invoking in render phase, where gl context is available
invokeInRender.put(method, notifier);
}
// wait until that test was invoked
waitUntilInvokedInRenderMethod();
}
/**
*
*/
private void waitUntilInvokedInRenderMethod() {
try {
while (true) {
Thread.sleep(10);
synchronized (invokeInRender) {
if (invokeInRender.isEmpty())
break;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,30 @@
// Taken from https://github.com/TomGrill/gdx-testing
package de.tomgrill.gdxtesting.examples;
import com.badlogic.gdx.Gdx;
import com.unciv.models.gamebasics.GameBasics;
import org.junit.Test;
import org.junit.runner.RunWith;
import de.tomgrill.gdxtesting.GdxTestRunner;
import static org.junit.Assert.assertTrue;
@RunWith(GdxTestRunner.class)
public class AssetExistsExampleTest {
@Test
public void gamePngExists() {
assertTrue("This test will only pass when the game.png exists",
Gdx.files.local("game.png").exists());
}
@Test
public void gameBasicsLoad() {
assertTrue("This test will only pass when the game.png exists",
GameBasics.INSTANCE.getBuildings().size() > 0);
}
}

View File

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright 2015 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package de.tomgrill.gdxtesting.examples;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class UnitTestExample {
@Test
public void oneEqualsOne() {
assertEquals(1, 1);
}
}