-
Notifications
You must be signed in to change notification settings - Fork 1
Test Writing for Code
Sharina Stubbs edited this page Sep 17, 2019
·
4 revisions
Tests get written in LibraryTest.java
Method gets written in Library.java
How many tests to write? Given limited time, write 2-3. Add in comments along the way of what tests I would write if I had time.
If you had enough time and were building a well tested app, you should write many tests.
- Test an array with 1 string
- An array with no strings
- Array that contains duplicate longest strings
- Longest string in beginning of array
- Longest string at end of array
We specify which test to run by putting @Test just above the method
@Test
public void testLongString() {
Library.LongString(new String[]{"a", "abcd", "ab"});
assertEquals(
message: "in this array, abcd should be the longest string",
expected: "abcd", "ab",
Library.longString(new String[]{"a", "abcd", "ab"})
);
}
@Test
public void testLongStringLength(){
assertEquals(
message: "spaces should count towards length",
expected: "hello world",
Library.longString(new String[]{"helloworld", "hello world"})
);
}
public static String longString(String[] arr) {
String answer = arr[0];
for(int i =1; i < arr.length; i++) {
answer = arr[i];
}
return answer;
}
}
Create it's own test file.