diff --git a/source/AccUnit/CodeCoverage/CodeCoverageTracker.cs b/source/AccUnit/CodeCoverage/CodeCoverageTracker.cs
index d1d5191..79884e3 100644
--- a/source/AccUnit/CodeCoverage/CodeCoverageTracker.cs
+++ b/source/AccUnit/CodeCoverage/CodeCoverageTracker.cs
@@ -20,9 +20,14 @@ public CodeCoverageTracker(VBProject vbProject)
public void Clear(string codeModuleName = null)
{
- if (codeModuleName.Length > 0)
+ if (!string.IsNullOrEmpty(codeModuleName))
{
RemoveCodeCoverageTracker(codeModuleName);
+ if (_codeModules.TryGetValue(codeModuleName, out var codeModuleTracker))
+ {
+ codeModuleTracker.Procedures.Clear();
+ _codeModules.Remove(codeModuleName);
+ }
}
else
{
diff --git a/source/Tests/AccUnit.Assertions.Tests/AccessCodeLib.AccUnit.Assertions.Tests.csproj b/source/Tests/AccUnit.Assertions.Tests/AccessCodeLib.AccUnit.Assertions.Tests.csproj
index 660bc3c..c03c8a2 100644
--- a/source/Tests/AccUnit.Assertions.Tests/AccessCodeLib.AccUnit.Assertions.Tests.csproj
+++ b/source/Tests/AccUnit.Assertions.Tests/AccessCodeLib.AccUnit.Assertions.Tests.csproj
@@ -105,6 +105,9 @@
prompt
+
+ ..\..\libvbide\Microsoft.Vbe.Interop.dll
+
..\..\packages\NUnit.3.13.3\lib\net45\nunit.framework.dll
@@ -114,6 +117,7 @@
+
diff --git a/source/Tests/AccUnit.Assertions.Tests/CodeCoverageTrackerTests.cs b/source/Tests/AccUnit.Assertions.Tests/CodeCoverageTrackerTests.cs
new file mode 100644
index 0000000..20e99aa
--- /dev/null
+++ b/source/Tests/AccUnit.Assertions.Tests/CodeCoverageTrackerTests.cs
@@ -0,0 +1,34 @@
+using AccessCodeLib.AccUnit.CodeCoverage;
+using NUnit.Framework;
+
+namespace AccessCodeLib.AccUnit.Assertions.Tests
+{
+ public class CodeCoverageTrackerTests
+ {
+ // An empty tracker needs no VBProject: nothing has to be removed from a code module.
+
+ [Test]
+ public void Clear_WithoutArgument_ClearsAllModulesWithoutException()
+ {
+ var tracker = new CodeCoverageTracker(null);
+
+ Assert.DoesNotThrow(() => tracker.Clear());
+ }
+
+ [Test]
+ public void Clear_WithNull_ClearsAllModulesWithoutException()
+ {
+ var tracker = new CodeCoverageTracker(null);
+
+ Assert.DoesNotThrow(() => tracker.Clear(null));
+ }
+
+ [Test]
+ public void Clear_WithEmptyString_ClearsAllModulesWithoutException()
+ {
+ var tracker = new CodeCoverageTracker(null);
+
+ Assert.DoesNotThrow(() => tracker.Clear(""));
+ }
+ }
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs b/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
index fd11951..e6c478d 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
@@ -1,4 +1,5 @@
using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
@@ -16,6 +17,7 @@
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
+[assembly: InternalsVisibleTo("AccUnit.VbeAddIn.Tests")]
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
diff --git a/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestListAndResultManager.cs b/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestListAndResultManager.cs
index 4a36963..2cfe321 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestListAndResultManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestListAndResultManager.cs
@@ -79,7 +79,14 @@ public VbideUserControl TestListAndResultWindow
{
_testListAndResultVbideControl = new VbideUserControl(AddIn, Resources.UserControls.TestResultUserControlInfoCaption, TestListAndResultViewUserControlInfo.PositionGuid);
_testListAndResultView = _testListAndResultVbideControl.Control;
- _testListAndResultView.RunBreakOnErrorMenuItemEnabled = (TestSuiteManager.TestSuite is AccessTestSuite);
+ try
+ {
+ _testListAndResultView.RunBreakOnErrorMenuItemEnabled = (TestSuiteManager.TestSuite is AccessTestSuite);
+ }
+ catch (Exception ex)
+ {
+ UITools.ShowException(ex);
+ }
_testListAndResultView.RunTests += TestListAndResultViewRunTests;
_testListAndResultView.ShowSourceCodeInvoked += TestListAndResultViewShowSourceCodeInvoked;
diff --git a/vbe-add-In/AccUnit.VbeAddIn/TestSuiteManager.cs b/vbe-add-In/AccUnit.VbeAddIn/TestSuiteManager.cs
index 4caa2c2..b0e5638 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/TestSuiteManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/TestSuiteManager.cs
@@ -61,14 +61,15 @@ private void InitTestSuite()
try
{
_vbaTestSuite = CreateVbaTestSuite(OfficeApplicationHelper);
+ TestSuiteInitialized?.Invoke(_vbaTestSuite);
}
catch (Exception ex)
{
- UITools.ShowException(ex);
- }
- finally
- {
- TestSuiteInitialized?.Invoke(_vbaTestSuite);
+ // Do not hand out a silent null: VBA would fail later with a meaningless message.
+ // The exception reaches VBA as COM error (Err.Description contains the message);
+ // UI callers show it themselves.
+ Logger.Log(ex);
+ throw new InvalidOperationException("AccUnit test suite could not be initialized: " + ex.Message, ex);
}
}
}
diff --git a/vbe-add-In/Tests/AccUnit.VbeAddIn.Tests/TestSuiteManagerTests.cs b/vbe-add-In/Tests/AccUnit.VbeAddIn.Tests/TestSuiteManagerTests.cs
new file mode 100644
index 0000000..ffb0b23
--- /dev/null
+++ b/vbe-add-In/Tests/AccUnit.VbeAddIn.Tests/TestSuiteManagerTests.cs
@@ -0,0 +1,25 @@
+using NUnit.Framework;
+using System;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn.Tests
+{
+ public class TestSuiteManagerTests
+ {
+ [Test]
+ public void TestSuite_WhenInitializationFails_ThrowsWithOriginalMessageInsteadOfReturningNull()
+ {
+ using (var manager = new TestSuiteManager())
+ {
+ manager.TestResultReporterRequest += (ref System.Collections.Generic.IList reporters) =>
+ throw new InvalidOperationException("reporter failure");
+ // no OfficeApplicationHelper => the suite cannot be created
+
+ var exception = Assert.Throws(() => { var _ = manager.TestSuite; });
+
+ Assert.That(exception.Message, Does.StartWith("AccUnit test suite could not be initialized"));
+ Assert.That(exception.InnerException, Is.Not.Null);
+ Assert.That(exception.Message, Does.Contain(exception.InnerException.Message));
+ }
+ }
+ }
+}