mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
Added tests for Travis to fail if the jsons don't parse or something
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -135,3 +135,4 @@ android/release/android.aab
|
|||||||
android/assets/maps/
|
android/assets/maps/
|
||||||
android/release/android.aab.sig
|
android/release/android.aab.sig
|
||||||
android/release/android-release.aab
|
android/release/android-release.aab
|
||||||
|
tests/build/
|
||||||
|
40
build.gradle
40
build.gradle
@ -128,7 +128,45 @@ project(":core") {
|
|||||||
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
|
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
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 {
|
tasks.eclipse.doLast {
|
||||||
delete ".project"
|
delete ".project"
|
||||||
|
@ -1 +1 @@
|
|||||||
include 'desktop', 'android', 'ios', 'html', 'core'
|
include 'desktop', 'android', 'ios', 'html', 'core', 'tests'
|
22
tests/build.gradle
Normal file
22
tests/build.gradle
Normal 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"
|
||||||
|
}
|
104
tests/src/de/tomgrill/gdxtesting/GdxTestRunner.java
Normal file
104
tests/src/de/tomgrill/gdxtesting/GdxTestRunner.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user