Created
November 21, 2023 09:32
-
-
Save toxicbloud/c0c25da812fda8870aecd5ebd1fe2b25 to your computer and use it in GitHub Desktop.
LibGDX Test Runner fot JUnit 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com; | |
import com.badlogic.gdx.Application; | |
import com.badlogic.gdx.ApplicationListener; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.backends.headless.HeadlessApplication; | |
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration; | |
import com.badlogic.gdx.graphics.GL20; | |
import org.junit.jupiter.api.extension.BeforeAllCallback; | |
import org.junit.jupiter.api.extension.ExtensionContext; | |
import static org.mockito.Mockito.mock; | |
/** | |
* GdxTestRunner class | |
* use to launch unit test with libGDX in headless mode. | |
* | |
* @author Antonin Rousseau , aka toxicbloud on GitHub | |
*/ | |
public class GdxTestRunner implements BeforeAllCallback, ApplicationListener { | |
/** | |
* The headless application. | |
*/ | |
private HeadlessApplication application; | |
@Override | |
public void beforeAll(ExtensionContext context) throws Exception { | |
HeadlessApplicationConfiguration config = new HeadlessApplicationConfiguration(); | |
application = new HeadlessApplication(this, config); | |
Gdx.gl = mock(GL20.class); | |
} | |
@Override | |
public void create() { | |
} | |
@Override | |
public void resize(int width, int height) { | |
} | |
@Override | |
public void render() { | |
} | |
@Override | |
public void pause() { | |
} | |
@Override | |
public void resume() { | |
} | |
@Override | |
public void dispose() { | |
} | |
/** | |
* Get the headless application. | |
* | |
* @return The headless application. | |
*/ | |
public Application getApplication() { | |
return application; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment