Skip to content

Commit

Permalink
Targets #420 - Error reporting - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alelom authored and Fraser Greenroyd committed Mar 8, 2023
1 parent b6a10ee commit c7b7e6e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,27 @@ public void LoadAssembliesShouldThrowException()

Should.Throw(() => testClass.LoadReferencedAssemblies(), typeof(FileLoadException));
}

[Test]
public void ErrorReportingPassingTest()
{
BH.Engine.Base.Compute.RecordError($"Some error logged via BH.Engine.Base.Compute.{nameof(Compute.RecordError)}");
Assert.Pass(); // Make it pass intentionally here; the recorded error should still make the test report failure on TearDown
}

[Test]
public void WarningReportingPassingTest()
{
BH.Engine.Base.Compute.RecordWarning($"Some warning logged via BH.Engine.Base.Compute.{nameof(Compute.RecordWarning)}");
Assert.Pass();
}


[Test]
public void NoteReportingPassingTest()
{
BH.Engine.Base.Compute.RecordNote($"Some note logged via BH.Engine.Base.Compute.{nameof(Compute.RecordNote)}");
Assert.Pass();
}
}
}
20 changes: 20 additions & 0 deletions NUnit_Engine/NUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,25 @@ public void LoadReferencedAssemblies()
$"\nMake sure that Copy Local is set to true for them in the test project {Path.GetFileNameWithoutExtension(projectFullPath)}." +
$"\nAlternatively, this could be because some of their dependencies were not referenced in the project.");
}

[TearDown]
public void LogRecordedEvents()
{
// This should check whether the test passed or not before dispatching to Warn/TextContext.

var events = BH.Engine.Base.Query.CurrentEvents();
if (events.Any())
{
foreach (var ev in events)
{
if (ev.Type == oM.Base.Debugging.EventType.Warning || ev.Type == oM.Base.Debugging.EventType.Error)
Assert.Warn($"{ev.Type}: {ev.Message}");
else
TestContext.Out.Write($"{ev.Type}: {ev.Message}");
}
}

BH.Engine.Base.Compute.ClearCurrentEvents();
}
}
}

0 comments on commit c7b7e6e

Please sign in to comment.