vendredi 30 mars 2018

testing methods that use android api

first post so sorry if I messed up. I am trying to write a test for a method that uses android.graphics.path, I am only using Junit (I think) and every time I try to execute the tests I get an error: java.lang.RuntimeException: Method moveTo in android.graphics.Path not mocked, I get a very similar error when testing methods that use graphics.Point, I don't know if i have missed something or if graphics objects cant be used in testing? (though the latter seems unlikely). any help on how I should be writing this test would be really appreciated!

@Test

public void createHorizontalLinesFromVerticesReturnsAnArrayListOfTheRightSize() {
    Grid grid = new Grid();
    ArrayList a = new ArrayList();
    a.add(new Coordinate(0 ,0));
    a.add(new Coordinate(333, 0));
    a.add(new Coordinate(666, 0));
    a.add(new Coordinate(999, 0));
    assertThat(grid.horizontalPaths.size(), is(GlobalParameters.getHorizontalLines()));
}

public ArrayListcreateHorizontalLinesFromVerticies(ArrayList list){

    ArrayList<Path> p = new ArrayList<>();
    Path path;
    for(Coordinate c : list){
        path = new Path();
        path.moveTo(c.getX(), c.getY());
        path.lineTo(c.getX(), Constants.getScreenHeight());
        p.add(path);
    }
    return p;
}

Aucun commentaire:

Enregistrer un commentaire