-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTEMPLATETest.java
75 lines (58 loc) · 2.33 KB
/
TEMPLATETest.java
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
import java.io.*;
import java.lang.reflect.*;
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
// Replace All "TEMPLATE" "LabClassName"
public class TEMPLATETest {
private static TEMPLATE tester = null;
private static ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private static PrintStream systemOut = System.out;
private static String log="";
private static boolean debug=false;
@Before //runs before every test
public void setupBeforeEachTest() throws Exception {
System.setOut(new PrintStream(outContent));
tester = new TEMPLATE();
}
@After //runs after every test
public void tearDownAfterEachTest() throws Exception {
System.setOut(systemOut);
}
@Test //Default Test
public void testOne() throws Exception{
assertTrue("Default test; replace!", false);
}
// Run after all tests complete
@AfterClass
public static void runafter(){
System.out.println("\n"+tester.getClass());
System.out.println("\nUser:\t\t\t" + System.getProperty("user.name"));
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println("Time:\t\t\t" + dtf.format(now));
System.out.println("Dir:\t\t\t" + System.getProperty("user.dir"));
System.out.println("JAVAHome:\t" + System.getProperty("java.home"));
System.out.println("JAVA Ven:\t" + System.getProperty("java.vendor"));
System.out.println("OS Arch:\t\t" + System.getProperty("os.arch"));
System.out.println("OS Name:\t\t" + System.getProperty("os.name"));
if(debug)
System.out.println(log);
}
//Run the main method and return output from stdout
public static String runMain(){
return runMain("");
}
//Run the main method, sending input to stdin, and return output from stdout
public static String runMain(String input){
System.setIn(new ByteArrayInputStream(input.getBytes()));
// set stdout
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
tester.main(null);
return baos.toString();
}
}