-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainTester.java
More file actions
110 lines (94 loc) · 3.91 KB
/
MainTester.java
File metadata and controls
110 lines (94 loc) · 3.91 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import java.io.*;
public class MainTester {
private static BufferedReader br;
public static int num = 0;
public static String test = "";
public static void main(String[] args) {
MainTester test = new MainTester();
test.setup(args);
}
public void setup(String[] args) {
// if no args specified, use defaults
if (args.length <= 0) {
String testObj = "EdgeField";
String attributeString = "1,testName";
System.out.println("Running default test with params: " + testObj + " " + attributeString);
runTest(testObj, attributeString);
return;
}
// else, use values specified
for (String arg : args) {
if (arg.toLowerCase().indexOf("-h") != -1) {
// Print help message
System.out.println("The following are a list of commands options:\n");
System.out.println("-n: what follows is the test object being tested");
System.out.println("\tEX. MainTester EdgeField -n \"1,testName\"");
System.out.println("-h help menu");
System.out.println("\tEX. MainTester -h");
System.out.println("-f: what follows is the name of a test object file");
System.out.println("\tEX. MainTester -f testobjectfile.txt");
System.out.println("\n\nThe following are examples of the full command prompt input:\n");
System.out.println("java -cp .:lib/junit-4.12.jar:lib/hamcrest-core-1.3.jar MainTester EdgeField -n \"1,testName\"");
System.out.println("java -cp .:lib/junit-4.12.jar:lib/hamcrest-core-1.3.jar MainTester -h");
System.out.println("java -cp .:lib/junit-4.12.jar:lib/hamcrest-core-1.3.jar MainTester -f testobjectfile.txt\n");
System.out.println("NOTE: You must specify the class name to be tested as well, which is before the command option (-n)");
break;
// For inline object definition
} else if (arg.toLowerCase().indexOf("-n") != -1) {
// Process test object
String testObject = args[0];
runTest(testObject, args[args.length-1]);
break;
// For datafile object definition
} else if (arg.toLowerCase().indexOf("-f") != -1) {
File dataFile = new File(args[args.length-1]);
try {
br = new BufferedReader(new FileReader(dataFile));
} catch(FileNotFoundException e) {
System.out.println("Specified file " + args[args.length-1] + "not found! Please try again.");
System.exit(0);
}
String currentLine = "";
try {
while ((currentLine = br.readLine()) != null) {
currentLine = currentLine.trim();
// Split the line into the TestObject Name and the Attribites
String[] arguments = currentLine.split(",", 2);
runTest(arguments[0], arguments[1]);
}
} catch(IOException e) {
System.out.println("IO Exception encountered when reading from data file.");
e.printStackTrace();
}
break;
}
}
}
public void runTest(String testObject, String attributeString) {
// Split the AttributeString into individual attributes
String[] attributes = attributeString.split(",", 0);
// Determine which test to run based on the specified TestObject name
if (testObject.toLowerCase().equals("edgefield")) {
num = Integer.parseInt(attributes[0]);
test = attributes[1];
EdgeFieldTest edgeFieldTest = new EdgeFieldTest();
Result result = JUnitCore.runClasses(EdgeFieldTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println("Was the test successful: " + result.wasSuccessful());
} else if (testObject.toLowerCase().equals("edgetable")) {
num = Integer.parseInt(attributes[0]);
test = attributes[1];
EdgeTableTest edgeTableTest = new EdgeTableTest();
Result result = JUnitCore.runClasses(EdgeTableTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println("Was the test successful: " + result.wasSuccessful());
}
}
}