java - Unit testing a method that uses reflection -
i trying unit test java methods one:
public boolean isint (object object){ homecoming object.getclass().equals(integer.class); }
this extremely simple illustration lets go it.
the question is: how can unit test (with junit) method without writing test each primitive type in java world? maybe concolic unit testing (jcute) answer?
please leave ideas, create test thorough possible less coding possible.
edit: goal of unit test check method returning right result type different integer, without having define set of tests checking types 1 one. when said primitives meant native types jdk (string, float, double, list, map, ...)
there limited list of primitive types: byte, short, int, long, boolean, char. each primitive has corresponding wrapper. that's it. so, easy write test each primitive type.
btw code cannot work primitieves because not objects, cannot phone call isint(123)
.
if want write shorter tests can write like:
@test public void isint() { asserttrue(obj.isint(new integer(1))); } @test public void isnotint() { (object obj : new object[] {new short(1), new boolean(true), new long(1), new chaeracter('a')}) { assertfalse(obj.isint(obj)); } }
junit supportes parametrized
tests. sounds overkill such simple case.
java unit-testing reflection junit
No comments:
Post a Comment