0

I've a very big problem: I can't run Unit Tests because of NullPointerException. I'll be more clear:

private Character c;
   private Sprite s;
   private Gioco1 g;
   private HeadlessApplicationConfiguration cfg;
   HeadlessApplication app;
   @Before
   public  void setUp() throws Exception {
      this.cfg = new HeadlessApplicationConfiguration();
      this.g= new Gioco1();
      this.app =new HeadlessApplication(g, cfg);
   }

   @Test
   public void testLeft(){      

      this.c=g.getPacman();
      c.left();
      assertEquals(c.getSprite().getX(),c.getSprite().getX()-2,0f);

}

The problem is that g.getPacman() returns an object of type Character (it's a class of mine) that is always NULL. Even if I try to istantiate a new Character with:

c = new Character("res/pacman.png");

it does not work. Here's the constructor of Character:

public Character(String img) {
      super(img);
      right=true;
      left=false;
      down=false;
      up=false;   
      Sprite=new Sprite(this);
   }

It gives a NullPointerException on super(img) where super is the constructor of Texture (Character extends Texture). How is this possible? It's like the test class does not recognize the internal path "res/pacman.png".

I've no idea on how do Unit Tests on this application.

May you help me?

Thanks a lot!

Leo91
  • 1,741
  • 3
  • 13
  • 20

0 Answers0