-
Notifications
You must be signed in to change notification settings - Fork 0
How to use testing framework
Alonso del Arte edited this page Dec 11, 2021
·
4 revisions
It's a lot like what you'd expect from other Java testing frameworks. At least the test writing part is.
[FINISH WRITING]
I like to start with a very minimal stub for the class to be tested.
package org.example.exercises.arithmetic;
public class Percentage {
private final int number;
public Percentage(int n) {
this.number = n;
}
}
The skeleton for the test class
package org.example.exercises.arithmetic;
import testframe.api.Test;
public class PercentageTest {
}
This is sufficient to get started writing tests. For example,
package org.example.exercises.arithmetic;
import testframe.api.Test;
public class PercentageTest {
@Test
public void testToString() {
int n = (int) Math.round(Math.random() * 100);
Percentage percentage = new Percentage(n);
String expected = n + ".0%";
String actual = percentage.toString();
assert expected.equals(actual);
}
}
If you run this, as explained in the next section, the output won't be very informative.
[FINISH WRITING]
[FINISH WRITING]