From f1259d5105ffb2d3c0dae235b95b36f2980c0682 Mon Sep 17 00:00:00 2001 From: Matteo Bitussi Date: Fri, 17 Nov 2023 13:30:16 +0100 Subject: [PATCH] Added logging of tests to log folder --- tool/src/main/java/migt/GUI.java | 1 + tool/src/main/java/migt/TestSuite.java | 40 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tool/src/main/java/migt/GUI.java b/tool/src/main/java/migt/GUI.java index b7a9c7c..1327dd0 100644 --- a/tool/src/main/java/migt/GUI.java +++ b/tool/src/main/java/migt/GUI.java @@ -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()) diff --git a/tool/src/main/java/migt/TestSuite.java b/tool/src/main/java/migt/TestSuite.java index ae780c3..a41b585 100644 --- a/tool/src/main/java/migt/TestSuite.java +++ b/tool/src/main/java/migt/TestSuite.java @@ -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; @@ -33,6 +38,41 @@ public TestSuite(String name, String description, List 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 getTests() { return tests; }