如何使用 cakebuild.net 构建 运行 xamarin 单元 test/ui 测试?
How to build run a xamarin unit test/ui test with cakebuild.net?
我目前有一个 Cake 构建脚本来在我的解决方案中构建我的个人项目,并且 运行 针对这些项目进行了一些 xUnit 测试。我还没有看到任何采用 Xamarin 单元测试应用程序或 UI 测试构建 dll 并 运行 将它们与 Cake 结合的文档或示例。我想知道这样的事情是否可能,如果可能的话如何?
我的蛋糕脚本:
#addin "Cake.Xamarin"
#tool "nuget:?package=xunit.runner.console"
#addin "nuget:?package=HyperLinq"
#addin "nuget:?package=XunitXmlResultParser"
//using XunitXmlResultParser;
// Arguments.
var target = Argument ("target", "Default");
var configuration = Argument ("configuration", "release");
// Define directories.
var solutionFile = GetFiles ("./OSP_POC.sln").First ();
// Android and iOS.
var androidProject = GetFiles ("./OSP_POC/OSP_POC.Android/*.csproj").First ();
var iOSProject = GetFiles ("./OSP_POC/OSP_POC.iOS/*.csproj").First ();
// stylecop settings file
var settingsFile = File ("Settings.stylecop");
// xml results file
var resultFile = File ("StylecopResults.xml");
// html report file
var htmlFile = File ("StylecopResults.html");
// Tests.
var testsProject = GetFiles ("./OSP_UnitTests/OSP_UnitTests.csproj").First ();
// NOTE: (assumes Tests projects end with .Tests).
var testsDllPath = string.Format ("./OSP_UnitTests/bin/{0}/netcoreapp2.0/OSP_UnitTests.dll", configuration);
// Output folders.
var artifactsDirectory = Directory ("./artifacts");
Task ("Clean")
.Does (() => {
CleanDirectories (string.Format ("./**/obj/{0}",
configuration));
CleanDirectories (string.Format ("./**/bin/{0}",
configuration));
Information ("Finished cleaning");
});
Task ("Restore-Packages")
.Does (() => {
NuGetRestore (solutionFile);
});
/*Task("StyleCop")
.Does(() =>
{
StyleCopAnalyse(settings => settings
.WithSolution(solutionFile)
.WithSettings(settingsFile)
.ToResultFile(resultFile)
.ToHtmlReport(htmlFile)
);
});*/
Task ("Run-Tests")
// Allows the build process to continue even if there Tests aren't passing.
.ContinueOnError ()
.IsDependentOn ("Prepare-Build")
.Does (() => {
Information ("running tests");
Information ($"{testsProject.FullPath}");
MSBuild (testsProject.FullPath, settings => settings
.SetConfiguration (configuration)
.WithTarget ("Build")
.SetVerbosity (Verbosity.Minimal));
DotNetCoreTool (testsProject,
"xunit",
"--no-build -noshadow -xml ../artifacts/report.xml -html ../artifacts/report.html -configuration " + configuration);
/*var setting = new DotNetCoreTestSettings{
Configuration = configuration,
ResultsDirectory = artifactsDirectory,
NoBuild = true
};
DotNetCoreTest(testsProject.FullPath, setting);
*/
/*XUnit2(testsDllPath,
new XUnit2Settings
{
HtmlReport = true,
OutputDirectory = artifactsDirectory
});*/
});
Task("Package-Results")
.IsDependentOn("Run-Tests")
.Does (() => {
var resultFile = GetFiles ("./artifacts/report.xml").First ().FullPath;
var parser = new XunitXmlResultParser.XParser ("IFS FSMx Test Results", resultFile, "./artifacts/test_results.html");
parser.Parse();
//var results = GetFiles("./artifacts/*.html");
//CopyFiles(results, @"\mkenas21\metrix$\RnD\Mobile\Osprey\build_results\");
});
Task ("Prepare-Build")
.IsDependentOn ("Clean")
.IsDependentOn ("Restore-Packages")
.Does (() => { });
Task ("Build-Android")
.IsDependentOn ("Prepare-Build")
.Does (() => {
MSBuild (androidProject, settings =>
settings.SetConfiguration (configuration)
.WithProperty ("DebugSymbols", "false")
.WithProperty ("TreatWarningsAsErrors", "false")
.WithTarget ("SignAndroidPackage")
.SetVerbosity (Verbosity.Minimal));
});
Task ("Build-iOS")
.IsDependentOn ("Prepare-Build")
.Does (() => {
MSBuild (iOSProject, settings =>
settings.SetConfiguration (configuration)
.WithProperty ("Platform", "iPhoneSimulator")
.WithProperty ("OutputPath", $"bin/iPhoneSimulator/{configuration}/")
.WithProperty ("DebugSymbols", "false")
.WithProperty ("TreatWarningsAsErrors", "false")
.SetVerbosity (Verbosity.Minimal));
});
Task ("Build-Solution")
.IsDependentOn ("Build-Android")
.IsDependentOn ("Build-iOS")
.Does (() => { });
Task ("Default")
.IsDependentOn ("Build-Solution")
.IsDependentOn ("Run-Tests")
.IsDependentOn ("Package-Results");
RunTarget (target);
我已经能够 运行 使用 xUnit 进行以下测试。我还没有解决的是运行在目标运行ner(iOS或Android)中将其[=]。但这确实执行了我的 .NET Core 单元测试。
DotNetCoreTest(UnitTestProjectPath, new DotNetCoreTestSettings
{
Configuration = "<Build Configuration>"
});
我目前有一个 Cake 构建脚本来在我的解决方案中构建我的个人项目,并且 运行 针对这些项目进行了一些 xUnit 测试。我还没有看到任何采用 Xamarin 单元测试应用程序或 UI 测试构建 dll 并 运行 将它们与 Cake 结合的文档或示例。我想知道这样的事情是否可能,如果可能的话如何? 我的蛋糕脚本:
#addin "Cake.Xamarin"
#tool "nuget:?package=xunit.runner.console"
#addin "nuget:?package=HyperLinq"
#addin "nuget:?package=XunitXmlResultParser"
//using XunitXmlResultParser;
// Arguments.
var target = Argument ("target", "Default");
var configuration = Argument ("configuration", "release");
// Define directories.
var solutionFile = GetFiles ("./OSP_POC.sln").First ();
// Android and iOS.
var androidProject = GetFiles ("./OSP_POC/OSP_POC.Android/*.csproj").First ();
var iOSProject = GetFiles ("./OSP_POC/OSP_POC.iOS/*.csproj").First ();
// stylecop settings file
var settingsFile = File ("Settings.stylecop");
// xml results file
var resultFile = File ("StylecopResults.xml");
// html report file
var htmlFile = File ("StylecopResults.html");
// Tests.
var testsProject = GetFiles ("./OSP_UnitTests/OSP_UnitTests.csproj").First ();
// NOTE: (assumes Tests projects end with .Tests).
var testsDllPath = string.Format ("./OSP_UnitTests/bin/{0}/netcoreapp2.0/OSP_UnitTests.dll", configuration);
// Output folders.
var artifactsDirectory = Directory ("./artifacts");
Task ("Clean")
.Does (() => {
CleanDirectories (string.Format ("./**/obj/{0}",
configuration));
CleanDirectories (string.Format ("./**/bin/{0}",
configuration));
Information ("Finished cleaning");
});
Task ("Restore-Packages")
.Does (() => {
NuGetRestore (solutionFile);
});
/*Task("StyleCop")
.Does(() =>
{
StyleCopAnalyse(settings => settings
.WithSolution(solutionFile)
.WithSettings(settingsFile)
.ToResultFile(resultFile)
.ToHtmlReport(htmlFile)
);
});*/
Task ("Run-Tests")
// Allows the build process to continue even if there Tests aren't passing.
.ContinueOnError ()
.IsDependentOn ("Prepare-Build")
.Does (() => {
Information ("running tests");
Information ($"{testsProject.FullPath}");
MSBuild (testsProject.FullPath, settings => settings
.SetConfiguration (configuration)
.WithTarget ("Build")
.SetVerbosity (Verbosity.Minimal));
DotNetCoreTool (testsProject,
"xunit",
"--no-build -noshadow -xml ../artifacts/report.xml -html ../artifacts/report.html -configuration " + configuration);
/*var setting = new DotNetCoreTestSettings{
Configuration = configuration,
ResultsDirectory = artifactsDirectory,
NoBuild = true
};
DotNetCoreTest(testsProject.FullPath, setting);
*/
/*XUnit2(testsDllPath,
new XUnit2Settings
{
HtmlReport = true,
OutputDirectory = artifactsDirectory
});*/
});
Task("Package-Results")
.IsDependentOn("Run-Tests")
.Does (() => {
var resultFile = GetFiles ("./artifacts/report.xml").First ().FullPath;
var parser = new XunitXmlResultParser.XParser ("IFS FSMx Test Results", resultFile, "./artifacts/test_results.html");
parser.Parse();
//var results = GetFiles("./artifacts/*.html");
//CopyFiles(results, @"\mkenas21\metrix$\RnD\Mobile\Osprey\build_results\");
});
Task ("Prepare-Build")
.IsDependentOn ("Clean")
.IsDependentOn ("Restore-Packages")
.Does (() => { });
Task ("Build-Android")
.IsDependentOn ("Prepare-Build")
.Does (() => {
MSBuild (androidProject, settings =>
settings.SetConfiguration (configuration)
.WithProperty ("DebugSymbols", "false")
.WithProperty ("TreatWarningsAsErrors", "false")
.WithTarget ("SignAndroidPackage")
.SetVerbosity (Verbosity.Minimal));
});
Task ("Build-iOS")
.IsDependentOn ("Prepare-Build")
.Does (() => {
MSBuild (iOSProject, settings =>
settings.SetConfiguration (configuration)
.WithProperty ("Platform", "iPhoneSimulator")
.WithProperty ("OutputPath", $"bin/iPhoneSimulator/{configuration}/")
.WithProperty ("DebugSymbols", "false")
.WithProperty ("TreatWarningsAsErrors", "false")
.SetVerbosity (Verbosity.Minimal));
});
Task ("Build-Solution")
.IsDependentOn ("Build-Android")
.IsDependentOn ("Build-iOS")
.Does (() => { });
Task ("Default")
.IsDependentOn ("Build-Solution")
.IsDependentOn ("Run-Tests")
.IsDependentOn ("Package-Results");
RunTarget (target);
我已经能够 运行 使用 xUnit 进行以下测试。我还没有解决的是运行在目标运行ner(iOS或Android)中将其[=]。但这确实执行了我的 .NET Core 单元测试。
DotNetCoreTest(UnitTestProjectPath, new DotNetCoreTestSettings
{
Configuration = "<Build Configuration>"
});