-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestRunner.java
More file actions
56 lines (48 loc) · 1.87 KB
/
TestRunner.java
File metadata and controls
56 lines (48 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static void main(String[] args) {
/*
* Change the name of the class to our Test file containing out JUnit Tests
*/
Result result = JUnitCore.runClasses(SortedStringSetTestMaster.class);
/*
* Set variables for deduction per failed test and total Possible Points.
*/
final int deduction = 4;
final int totalPossible = 50;
int count = 0; // Counter for deductions
if(result.wasSuccessful()) {
System.out.println("Perfect JUnit Run!");
System.out.println();
System.out.println();
return;
}
System.out.println("Methods Failed:");
for (Failure failure : result.getFailures()) {
String name = failure.getTestHeader(); // Get the method name failed
name = name.substring(0, name.indexOf("(")); // Remove the call name
if (name.substring(0, 10).equals("testFailed")) {
//Remove testFailed from the name
System.out.println(name.substring(10, name.length()));
}else {
// If no testFailed text is present just print failed Method Name
System.out.println(name);
}
//Remove comments if detailed reason on failure of test case is needed
//System.out.println(" Reason - " + failure.getMessage());
count += deduction;
}
System.out.println();
System.out.println("Your Point Deduction ---> -" + count);
System.out.println("Your Final Score -------> " + (totalPossible - count) + "/" + totalPossible + " ("
+ (percent(totalPossible, count) * 100) + "%)");
System.out.println();
System.out.println();
}
// Calculate the Percent that was received and return as a double.
private static double percent(int totalPossible, int count) {
return (double) (totalPossible - count) / (double) totalPossible;
}
}