I am trying to unit test the core
package of my libgdx application.
What is the best way to mock the ShaderProgram
such that the root class may be tested?
Given the following init for a Libgdx test runner,
init {
val conf = HeadlessApplicationConfiguration()
HeadlessApplication(this, conf)
Gdx.gl = mock(GL20::class.java)
Gdx.gl20 = mock(GL20::class.java)
Gdx.gl30 = mock(GL30::class.java)
Gdx.graphics = mock(Graphics::class.java)
`when`(Gdx.graphics.height).thenReturn(dimensions)
`when`(Gdx.graphics.width).thenReturn(dimensions)
}
and the function under test (which is in a class that is a child of Application Listener
),
override fun create() {
...
stage = Stage(ScreenViewport())
...
}
an error occurs inside of Stage when it attempts to compile a shader.
I.e., in SpriteBatch.java
from com.badlogic.gdx.graphics.g2d
,
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
shader.isCompiled()
appears to always return false for a HeadlessApplication
.