Giter VIP home page Giter VIP logo

gdx-testing's Introduction

gdx-testing

This is a skeleton for libGDX projects which require testing with JUnit and Mockito.

Updates & News

Follow me to receive release updates about this and my other projects (Promise: No BS posts)

https://twitter.com/TomGrillGames and https://www.facebook.com/tomgrillgames

I will also stream sometimes when developing at https://www.twitch.tv/tomgrill and write a blog article from time to time at http://tomgrill.de

Installation

Asuming that you already did setup a libGDX project:

  • Copy the tests folder of this project into your libGDX root directory.

  • Edit the settings.gradle file and add the 'tests' subproject to the includes like this:

include 'desktop', 'android', 'ios', 'html', 'core', 'tests'
  • Edit build.gradle file, and add these lines:
project(":tests") {
    apply plugin: "java"

    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(":android")
//        compile project(":html")
//        compile project(":desktop")
        
        
//        if(System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0) {
//        	compile project(":ios")
//        }
        
        compile project(":core")
        
        compile "junit:junit:4.+"
        compile "org.mockito:mockito-all:1.9.+"
        
        compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"        

        testCompile 'junit:junit:4.+'
        testCompile "org.mockito:mockito-all:1.9.+"

        testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
        testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
        testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    }
}
  • Import the project to your IDE
  • Refresh your gradle dependencies.

Run the tests

./gradlew tests:test

Note: gradle caches passed tests. So if you rename/move/delete badlogic.jpg and run the tests again it will pass. Run from time to time (especially when working with tests against filesystem or anything else that has changed but did not affect the compiled tests):

./gradlew clean tests:test

Whenever you require a headless libGDX environment for your tests to pass, copy the tests/src/de/tomgrill/gdxtesting/GdxTestRunner.java file to your tests project and annotate your test class with:

@RunWith(GdxTestRunner.class)
public class MySuperTestClass {
	@Test
	public void bestTestInHistory() {
	
	}
}

Happy testing!

##License

The gdx-testing project is licensed under the Apache 2 License, meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.

##Source & inspired by

http://shahmirj.com/blog/getting-junit-working-with-libgdx-in-gradle

http://badlogicgames.com/forum/viewtopic.php?f=17&t=1485

gdx-testing's People

Contributors

tomgrill avatar beegodwin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.