Skip to content

Commit

Permalink
Merge pull request #9 from RalfVio/Task908695
Browse files Browse the repository at this point in the history
New feature: Log file with execution statistics
  • Loading branch information
RalfVio authored Feb 12, 2024
2 parents 01c682c + ad86c64 commit a6036eb
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 6 deletions.
11 changes: 11 additions & 0 deletions SQLiteConnector/BusinessObjects/TestStepResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ private static string HtmlDecode(string html)

return result.ToString();
}
public bool IsPassedOrFailed()
{
switch (Outcome)
{
case "Passed":
case "Failed":
return true;
default:
return false;
}
}
}

public class TestResultIteration
Expand Down
29 changes: 29 additions & 0 deletions STI Test Report/Pdf/PdfSTITestReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ enum eLastPrinted {first,testSuite, testPoint, testResult ,testAction, associate
eLastPrinted lastPrinted = eLastPrinted.first;

bool _showFullReport = true;

public class TestPointStatus
{
public int RunId { get; set; }
public int TestCaseId { get; set; }
public int PageNumber { get; set; }
public bool TestCaseNotApproved { get; set; }
public bool NoTestSteps { get; set; }
public bool NotRun { get; set; }

public string ErrorMessage()
{
string result = null;
if (TestCaseNotApproved)
result = (result == null ? "" : result+", ")
+ "tc not approved";
if (NoTestSteps)
result = (result == null ? "" : result + ", ")
+ "no steps";
if (NotRun)
result = (result == null ? "" : result + ", ")
+ "active";

return result;
}
public bool TestIsOk() => !(TestCaseNotApproved || NoTestSteps || NotRun);
}

public void PrintStart(TestPlan testPlan, int suiteMaxLevelInContentList, bool showFullReport)
{
_testPlan = testPlan; _suiteMaxLevelInContentList=suiteMaxLevelInContentList;
Expand Down Expand Up @@ -549,6 +577,7 @@ List<string> SplitToMultiLine(string text, double maxLen, double maxLenFirstLine

return result;
}
public int GetPageNumber() => _doc.PageCount;

PdfPage _actualPage = null;
void CreatePage()
Expand Down
16 changes: 15 additions & 1 deletion STI Test Report/ReportOptionsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions STI Test Report/ReportOptionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private void ReportOptionsForm_Shown(object sender, EventArgs e)
this.noTestResults_checkBox.Checked = Program.UserSettings.OptionNoTestResults;
this.noTestSteps_checkBox.Checked = Program.UserSettings.OptionNoTestSteps;
this.testSuite_TextBox.Text = Program.UserSettings.GetTestSuiteIds() ?? "";
this.writeLogFile_checkBox.Checked = Program.UserSettings.WriteLogFile;
}

public class ReportOptions
Expand All @@ -24,6 +25,7 @@ public class ReportOptions
public bool LastTestRun { get; set; }
public bool NoTestResults { get; set; }
public bool NoTestSteps { get; set; }
public bool WriteLogFile { get; set; }
public List<int> TestSuiteIds { get; set; }

}
Expand Down Expand Up @@ -51,6 +53,7 @@ private void Create_Button_Click(object sender, EventArgs e)
NoTestResults = this.noTestResults_checkBox.Checked,
NoTestSteps = this.noTestSteps_checkBox.Checked,
TestSuiteIds = testSuiteIds,
WriteLogFile = this.writeLogFile_checkBox.Checked,
};

Program.UserSettings.OptionNotRun = _reportOptions.NotRun;
Expand All @@ -59,6 +62,7 @@ private void Create_Button_Click(object sender, EventArgs e)
Program.UserSettings.OptionNoTestResults = _reportOptions.NoTestResults;
Program.UserSettings.OptionNoTestSteps = _reportOptions.NoTestSteps;
Program.UserSettings.TestSuiteIds = _reportOptions.TestSuiteIds;
Program.UserSettings.WriteLogFile = _reportOptions.WriteLogFile;

DialogResult = DialogResult.OK;
}
Expand Down
6 changes: 3 additions & 3 deletions STI Test Report/STI Test Report.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>Bhakthavathsala R B, Ralf Viola</Authors>
<Copyright>©Philips 2023</Copyright>
<Copyright>©Philips 2024</Copyright>
<Company>Philips</Company>
<ProductName>STI Test Report</ProductName>
<StartupObject>STI_Test_Report.Program</StartupObject>
<Version>1.0.1.5</Version>
<FileVersion>1.0.1.5</FileVersion>
<Version>1.0.2.0</Version>
<FileVersion>1.0.2.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
49 changes: 47 additions & 2 deletions STI Test Report/StartForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,14 @@ private async void print_button_Click(object sender, EventArgs e)
return;

_reportFileName = pdf_SaveFileDialog.FileName;
string logFilePath = Path.GetDirectoryName(_reportFileName) + "\\" + Path.GetFileNameWithoutExtension(_reportFileName) + ".txt";

try
{
if (File.Exists(_reportFileName))
File.Delete(_reportFileName);
if (File.Exists(logFilePath))
File.Delete(logFilePath);
}
catch { this.status_toolStripStatusLabel.Text = "File is locked."; return; }

Expand All @@ -196,7 +200,7 @@ private async void print_button_Click(object sender, EventArgs e)

this.Cursor = Cursors.WaitCursor;

await Task.Run(() => CreateReport(_reportFileName, dbFilePath, reportOptions));
await Task.Run(() => CreateReport(_reportFileName, logFilePath, dbFilePath, reportOptions));

this.open_linkLabel.Visible = File.Exists(_reportFileName);
this.status_toolStripStatusLabel.Text = "Done";
Expand Down Expand Up @@ -297,13 +301,15 @@ void PrintControls(bool enable, bool dbExists)
if (!enable)
this.open_linkLabel.Visible = false;
}
void CreateReport(string pdfFilePath, string dbFilePath, ReportOptionsForm.ReportOptions reportOptions)
void CreateReport(string pdfFilePath, string logFilePath, string dbFilePath, ReportOptionsForm.ReportOptions reportOptions)
{
var sqlLiteBL = new SQLiteConnector.BL();
sqlLiteBL.OpenDatabase(dbFilePath);
var testPlan = sqlLiteBL.TestPlanRead();
var pdfReport = new OutPdf.PdfSTITestReport();

Dictionary<int, OutPdf.PdfSTITestReport.TestPointStatus> testPointStati = new();

pdfReport.PrintStart(testPlan, 1, true);

var testSuites = sqlLiteBL.TestSuitesRead(reportOptions.TestSuiteIds);
Expand Down Expand Up @@ -338,13 +344,22 @@ void CreateReport(string pdfFilePath, string dbFilePath, ReportOptionsForm.Repor
if (reportOptions.NoTestResults)
continue;

testPointStati.Add(testPoint.Id, new OutPdf.PdfSTITestReport.TestPointStatus() { TestCaseId = testPoint.TestCaseId, PageNumber = pdfReport.GetPageNumber(), NotRun = testPoint.LastTestRunId <= 0 });

var testResults = sqlLiteBL.TestResultsRead(testPoint, reportOptions.LastTestRun ? testPoint.LastTestRunId : (int?)null);
foreach (var testResult in testResults)
{
pdfReport.Print(testResult, null);

testPointStati[testPoint.Id].RunId = testResult.RunId;
if (testResult.TestCaseState != "Approved")
testPointStati[testPoint.Id].TestCaseNotApproved = true;

if (!reportOptions.NoTestSteps)
{
var steps = testResult.GetTestCaseSteps();
if (steps == null || steps.Count == 0 || testResult.Iterations == null)
testPointStati[testPoint.Id].NoTestSteps = true;
if (testResult.Iterations != null)
foreach (var iteration in testResult.Iterations)
{
Expand All @@ -358,6 +373,8 @@ void CreateReport(string pdfFilePath, string dbFilePath, ReportOptionsForm.Repor
var actionResult = actionResults.Where(ar => ar.StepIdentifier == step.GetStepIdentifier()).FirstOrDefault();
step.Outcome = (actionResult == null ? "" : actionResult.Outcome);
step.Comment = (actionResult == null ? "" : actionResult.ErrorMessage);
if (!step.IsPassedOrFailed())
testPointStati[testPoint.Id].NoTestSteps = true;

if (parameterResults != null)
step.Parameters = parameterResults.Where(ar => ar.StepIdentifier == step.GetStepIdentifier()).ToList();
Expand All @@ -377,6 +394,8 @@ void CreateReport(string pdfFilePath, string dbFilePath, ReportOptionsForm.Repor
var sharedStepsActionResult = actionResults.Where(ar => ar.StepIdentifier == sharedStepsStep.GetStepIdentifier()).FirstOrDefault();
sharedStepsStep.Outcome = (sharedStepsActionResult == null ? "" : sharedStepsActionResult.Outcome);
sharedStepsStep.Comment = (sharedStepsActionResult == null ? "" : sharedStepsActionResult.ErrorMessage);
if (!sharedStepsStep.IsPassedOrFailed())
testPointStati[testPoint.Id].NoTestSteps = true;
pdfReport.Print(sharedStepsStep);
}
}
Expand Down Expand Up @@ -409,6 +428,32 @@ void CreateReport(string pdfFilePath, string dbFilePath, ReportOptionsForm.Repor
fs.Close();
}

if (reportOptions.WriteLogFile)
using (var sw = new StreamWriter(logFilePath, false, System.Text.Encoding.UTF8))
{
sw.WriteLine($"Test Plan:\t{testPlan.TitleId}\r\n");
int total = testPointStati.Count();
sw.WriteLine($"Total test points:\t{total}");
int count = testPointStati.Count(tp => tp.Value.TestIsOk() && !tp.Value.NotRun);
sw.WriteLine($"Correct:\t{count} {((double)count / total):P1}");
count = testPointStati.Count(tp => !tp.Value.TestIsOk() && !tp.Value.NotRun);
sw.WriteLine($"Incorrect:\t{count} {((double)count / total):P1}");
count = testPointStati.Count(tp => tp.Value.TestCaseNotApproved && !tp.Value.NotRun);
sw.WriteLine($" TC not approved:\t{count} {((double)count / total):P1}");
count = testPointStati.Count(tp => tp.Value.NoTestSteps && !tp.Value.NotRun);
sw.WriteLine($" No step details:\t{count} {((double)count / total):P1}");
count = testPointStati.Count(tp => tp.Value.NotRun);
sw.WriteLine($"Active:\t{count} {((double)count / total):P1}");

sw.WriteLine($"\r\nErrors:");
sw.WriteLine($"\r\nRun Id\tTest Case Id\tPage\tError");
foreach (var id in testPointStati.Keys)
{
var testPointStatus = testPointStati[id];
if (!testPointStatus.TestIsOk())
sw.WriteLine($"{(testPointStatus.RunId<=0?"":testPointStatus.RunId.ToString())}\t{testPointStatus.TestCaseId}\t{testPointStatus.PageNumber}\t{testPointStatus.ErrorMessage()}");
}
}
}


Expand Down
2 changes: 2 additions & 0 deletions STI Test Report/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class UserSettings
public bool OptionNoTestSteps { get; set; }

public List<int> TestSuiteIds { get; set; }
public bool WriteLogFile { get; set; }

public string GetTestSuiteIds()
{
if (TestSuiteIds == null || TestSuiteIds.Count == 0)
Expand Down

0 comments on commit a6036eb

Please sign in to comment.