Creating Texture in headless LibGDX unit tests

后端 未结 1 1210
心在旅途
心在旅途 2021-01-05 03:23

I am using the LibGDX headless backend to run jUnit tests. This works well for certain tests, but if I try to create a new Texture(\'myTexture.png\');, I get a

相关标签:
1条回答
  • 2021-01-05 03:49

    Mocking the Gdx.gl help me solved this NullPointerException during Texture creation:

    import static org.mockito.Mockito.mock;
    
    ...
    
    Gdx.gl = mock(GL20.class);
    

    I used it with GdxTestRunner, see https://bitbucket.org/TomGrill/libgdx-testing-sample

    public GdxTestRunner(Class<?> klass) throws InitializationError {
        super(klass);
        HeadlessApplicationConfiguration conf = new HeadlessApplicationConfiguration();
        new HeadlessApplication(this, conf);
        Gdx.gl = mock(GL20.class); // my improvement
    }
    
    0 讨论(0)
提交回复
热议问题