Skip to content

Commit

Permalink
Merge pull request #38 from nunit/issue-37
Browse files Browse the repository at this point in the history
Perform integration tests on packages
  • Loading branch information
CharliePoole authored Mar 31, 2020
2 parents 1f27deb + 5d24095 commit 1adff36
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 9 deletions.
89 changes: 87 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#tool nuget:?package=NUnit.ConsoleRunner&version=3.8.0
#tool nuget:?package=NUnit.ConsoleRunner&version=3.11.1

//////////////////////////////////////////////////////////////////////
// PROJECT-SPECIFIC
Expand Down Expand Up @@ -89,6 +89,12 @@ if (BuildSystem.IsRunningOnAppVeyor)
AppVeyor.UpdateBuildVersion(packageVersion);
}

Teardown(context =>
{
// Make sure we don't leave a test extension installed
ClearDriverExtensions();
});

//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
Expand All @@ -98,6 +104,16 @@ var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
var BIN_SRC = BIN_DIR; // Source of binaries used in packaging
var OUTPUT_DIR = PROJECT_DIR + "output/";
var TOOLS_DIR = PROJECT_DIR + "tools/";

// Console Runner
var CONSOLE_EXE = TOOLS_DIR + "NUnit.ConsoleRunner/tools/nunit3-console.exe";

// Packages
var NUGET_PACKAGE_NAME = NUGET_ID + "." + VERSION + ".nupkg";
var CHOCO_PACKAGE_NAME = CHOCO_ID + "." + VERSION + ".nupkg";
var NUGET_PACKAGE = OUTPUT_DIR + NUGET_PACKAGE_NAME;
var CHOCO_PACKAGE = OUTPUT_DIR + CHOCO_PACKAGE_NAME;

// Adjust BIN_SRC if --binaries option was given
if (binaries != null)
Expand Down Expand Up @@ -182,7 +198,6 @@ Task("Test")
.Does(() =>
{
NUnit3(BIN_DIR + UNIT_TEST_ASSEMBLY);
NUnit3(BIN_DIR + INTEGRATION_TEST_ASSEMBLY);
});

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -279,6 +294,65 @@ Task("RePackageChocolatey")
});
});

//////////////////////////////////////////////////////////////////////
// PACKAGE TESTS
//////////////////////////////////////////////////////////////////////

Task("TestNuGetPackage")
.IsDependentOn("RePackageNuGet")
.Does(() =>
{
RunPackageTests(NUGET_ID);
});

Task("TestChocolateyPackage")
.IsDependentOn("RePackageChocolatey")
.Does(() =>
{
RunPackageTests(CHOCO_ID);
});

private void RunPackageTests(string packageId)
{
InstallPackage(packageId);

NUnit3(BIN_DIR + INTEGRATION_TEST_ASSEMBLY);
}

private void InstallPackage(string packageId)
{
ClearDriverExtensions();

NuGetInstall(packageId, new NuGetInstallSettings()
{
Source = new [] { OUTPUT_DIR },
OutputDirectory = TOOLS_DIR
});

// Our copy of NUnit3-console is looking for nuget extensions,
// rather than the chocolatey-formatted version. We fake it
// by treating the package as a nuget extension, installing
// it and then renaming the directory. For simplicity, we do
// the mmove for both package types.

MoveDirectory(TOOLS_DIR + packageId + "." + VERSION, TOOLS_DIR + NUGET_ID );
}

// Remove all driver extensions, both nuget and chocolatey, so that we are
// sure that we are testing the extension we want to test.
private void ClearDriverExtensions()
{
// Delay in case a prior test run is holding open assemblies we want to delete
System.Threading.Thread.Sleep(1000);

var driverExtensionDirectories = GetDirectories(TOOLS_DIR + NUGET_ID + "*");
driverExtensionDirectories.Add(GetDirectories(TOOLS_DIR + CHOCO_ID + "*"));
DeleteDirectories(driverExtensionDirectories, new DeleteDirectorySettings()
{
Recursive = true
});
}

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Expand All @@ -295,6 +369,11 @@ Task("RePackage")
.IsDependentOn("RePackageNuGet")
.IsDependentOn("RePackageChocolatey");

Task("TestPackages")
.IsDependentOn("Package")
.IsDependentOn("TestNuGetPackage")
.IsDependentOn("TestChocolateyPackage");

Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
Expand All @@ -304,6 +383,12 @@ Task("Travis")
.IsDependentOn("Build")
.IsDependentOn("Test");

Task("All")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package")
.IsDependentOn("TestPackages");

Task("Default")
.IsDependentOn("Build");

Expand Down
7 changes: 0 additions & 7 deletions src/extension/nunit.v2.driver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir $(SolutionDir)tools\NUnit.Extension.V2FrameworkDriver\tools
copy $(TargetPath) $(SolutionDir)tools\NUnit.Extension.V2FrameworkDriver\tools
copy $(TargetDir)nunit.core.dll $(SolutionDir)tools\NUnit.Extension.V2FrameworkDriver\tools
copy $(TargetDir)nunit.core.interfaces.dll $(SolutionDir)tools\NUnit.Extension.V2FrameworkDriver\tools
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
1 change: 1 addition & 0 deletions tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.29.0" />
<package id="NUnit.ConsoleRunner" version="3.11.1" />
</packages>

0 comments on commit 1adff36

Please sign in to comment.