Skip to content

Commit

Permalink
Merge pull request #63 from nunit/issue-62
Browse files Browse the repository at this point in the history
Automatically skip non-test assemblies when loading solution
  • Loading branch information
CharliePoole authored Sep 26, 2021
2 parents 5a69b9c + 1df266e commit e0ab8a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/extension/VSSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public TestPackage GetTestPackage(string configName)
}
}

package.AddSetting("SkipNonTestAssemblies", true);

return package;
}

Expand Down
50 changes: 24 additions & 26 deletions src/tests/SolutionLoadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public void VS2003Solution()
{
IProject project = _loader.LoadFrom(file.Path);

Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(4, project.GetTestPackage("Debug").SubPackages.Count);
Assert.AreEqual(4, project.GetTestPackage("Release").SubPackages.Count);
PerformStandardChecks(project, 4, 4);
}
}

Expand All @@ -59,9 +57,7 @@ public void VS2005Solution()
{
IProject project = _loader.LoadFrom(file.Path);

Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(4, project.GetTestPackage("Debug").SubPackages.Count);
Assert.AreEqual(4, project.GetTestPackage("Release").SubPackages.Count);
PerformStandardChecks(project, 4, 4);
}
}

Expand All @@ -72,13 +68,12 @@ public void SolutionWithMultiplePlatforms()
using (TestResource file = new TestResource("solution-with-multiple-platforms.sln"))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.That(project.ConfigNames, Is.EqualTo(new[] { "Debug", "Release" }));
PerformStandardChecks(project, 3, 3);

string tempDir = Path.GetDirectoryName(file.Path);
foreach (string config in project.ConfigNames)
{
var subPackages = project.GetTestPackage(config).SubPackages;
Assert.That(subPackages.Count, Is.EqualTo(3));
Assert.That(subPackages[0].FullName, Is.EqualTo(
$"{tempDir}\\bin\\{config}\\MultiplePlatformProject.dll"));
Assert.That(subPackages[1].FullName, Is.EqualTo(
Expand All @@ -96,10 +91,8 @@ public void SolutionWithWebApplication()
using (TestResource file = new TestResource("solution-with-web-application.sln"))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.AreEqual(2, project.ConfigNames.Count);
// Web project is ignored
Assert.AreEqual(1, project.GetTestPackage("Debug").SubPackages.Count);
Assert.AreEqual(1, project.GetTestPackage("Release").SubPackages.Count);
PerformStandardChecks(project, 1, 1);
}
}

Expand All @@ -112,9 +105,7 @@ public void SolutionWithUnmanagedCpp()
{
IProject project = _loader.LoadFrom(file.Path);

Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(2, project.GetTestPackage("Debug").SubPackages.Count);
Assert.AreEqual(2, project.GetTestPackage("Release").SubPackages.Count);
PerformStandardChecks(project, 2, 2);
}
}

Expand All @@ -126,9 +117,7 @@ public void SolutionWithDisabledProject()
using (TestResource file = new TestResource("solution-with-disabled-project.sln"))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(2, project.GetTestPackage("Release").SubPackages.Count, "Release should have 2 assemblies");
Assert.AreEqual(1, project.GetTestPackage("Debug").SubPackages.Count, "Debug should have 1 assembly");
PerformStandardChecks(project, 1, 2);
}
}

Expand All @@ -140,9 +129,7 @@ public void SolutionWithNonNunitTestProject()
using (TestResource file = new TestResource("solution-with-non-nunit-project.sln"))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(2, project.GetTestPackage("Release").SubPackages.Count, "Release should have 2 assemblies");
Assert.AreEqual(2, project.GetTestPackage("Debug").SubPackages.Count, "Debug should have 2 assemblies");
PerformStandardChecks(project, 2, 2);
}
}

Expand All @@ -153,9 +140,7 @@ public void SolutionWithProjectUsingPackageReference()
using (TestResource file = new TestResource("solution-with-package-reference.sln"))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(1, project.GetTestPackage("Release").SubPackages.Count, "Release should have 1 assemblies");
Assert.AreEqual(1, project.GetTestPackage("Debug").SubPackages.Count, "Debug should have 1 assembly");
PerformStandardChecks(project, 1, 1);
}
}

Expand All @@ -166,10 +151,23 @@ public void SolutionWithMultipleRuntimes()
using (TestResource file = new TestResource("solution-multiple-frameworks.sln"))
{
IProject project = _loader.LoadFrom(file.Path);
Assert.AreEqual(2, project.ConfigNames.Count);
Assert.AreEqual(3, project.GetTestPackage("Release").SubPackages.Count, "Release should have 3 assemblies");
Assert.AreEqual(3, project.GetTestPackage("Debug").SubPackages.Count, "Debug should have 3 assemblies");
PerformStandardChecks(project, 3, 3);
}
}

private void PerformStandardChecks(IProject project, int dbgCount, int relCount)
{
Assert.That(project.ConfigNames, Is.EqualTo(new object[] { "Debug", "Release" }));

var package = project.GetTestPackage("Debug");
Assert.That(package.SubPackages.Count,
Is.EqualTo(dbgCount), $"Debug should have {dbgCount} assemblies");
Assert.That(package.Settings.ContainsKey("SkipNonTestAssemblies"));

package = project.GetTestPackage("Release");
Assert.That(package.SubPackages.Count,
Is.EqualTo(relCount), $"Release should have {relCount} assemblies");
Assert.That(package.Settings.ContainsKey("SkipNonTestAssemblies"));
}
}
}

0 comments on commit e0ab8a7

Please sign in to comment.