Issue
I have this problem where I have to test if an array has a length of 3.
private Number[] number;
Here's my test to check if my array has a length of 3
@Test
void arrayHasALengthOf3(){
Number[] number;
assertTrue(number == 3);
}
I don't really know how I can solve this so can you guys help me out ...
Solution
One of the possible solutions.
@Test
void arrayHasALengthOf3() {
final int EXPECTED_LENGTH = 3;
Number[] number = new Number[EXPECTED_LENGTH]; // you need to initialize it.
// Use number.length to get the length of the array.
assertEquals(number.length, EXPECTED_LENGTH);
}
You can either initialize the array with a class that contains Number[]
in it.
Your main problem was how you defined the array & how you check for the length.
Answered By - Math
Answer Checked By - David Marino (JavaFixing Volunteer)