I am currently writing a Junit testing suite for certain codes.
What I am doing is, there is a class called Person, in which its constructor has variables of name, height, and weight.
In its constructor, it throws an exception if the number of characters for the name is longer than 20.
If the test needs to test that the constructor does not accept names longer than 20 characters, how should I write a test method?
For example, if I write:
@Test (expected = IllegalArgumentException.class)
public void testPersoin() {
Person person = new Person("BobBobBobBobBobBobBobBobBobBobBobBobBobBobBobBobBobBob", "172", "62");
}
and when I run it, it would pass the test case, but it is only testing the length of the name: "BobBobBobBobBobBobBobBobBobBobBobBobBobBobBobBobBobBob", but not any longer or shorter names.
Is there any proper way that tests whether the character of names is longer than 20 or not? Should I write if/else condition in a test method? How should I demonstrate the boundaries of if in a test suite?
Thanks!