Skip to content

Commit

Permalink
Added logging of tests to log folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mattebit committed Nov 17, 2023
1 parent bf3f251 commit f1259d5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions tool/src/main/java/migt/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ public void onExecuteStart() {
public void onExecuteDone() {
if (passives.size() == 0) {
update_gui_test_results();
testSuite.log_test_suite(LOG_FOLDER);

lblOutput.setText("Done. Executed Passive Tests: "
+ (passives.isEmpty() ? 0 : passives.size())
Expand Down
40 changes: 40 additions & 0 deletions tool/src/main/java/migt/TestSuite.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package migt;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -33,6 +38,41 @@ public TestSuite(String name, String description, List<Test> tests) {
this.tests = tests;
}

public void log_test_suite(String log_folder_path) {
String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm").format(new java.util.Date());
String test_log_folder = log_folder_path + "/" + timestamp + "/suite_" + this.name + "/";

File directory = new File(test_log_folder);
if (!directory.exists()) {
if (!directory.mkdirs()) {
System.err.println("cannot create log directory at " + test_log_folder);
}
}

String log_content = "";
log_content += "| test name | description | type | result | applicable |\n";
log_content += "|-----------|-------------|------|--------|------------|\n";

for (Test t : tests) {
log_content += "|" + t.name +
"|" + t.description +
"|" + (t.isActive ? "active" : "passive") +
"|" + t.success +
"|" + t.applicable + "|\n";
}

File log_message = new File(test_log_folder + "results.md");
try {
FileWriter fw = new FileWriter(log_message.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(log_content);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}


public List<Test> getTests() {
return tests;
}
Expand Down

0 comments on commit f1259d5

Please sign in to comment.