/// <summary> /// Uploads test results XML file to AppVeyor. Results type can be one of the following: mstest, xunit, nunit, nunit3, junit. /// </summary> /// <param name="path">The file path of the test results XML to upload.</param> /// <param name="resultsType">The results type. Can be mstest, xunit, nunit, nunit3 or junit.</param> public void UploadTestResults(FilePath path, AppVeyorTestResultsType resultsType) { if (path == null) { throw new ArgumentNullException("path"); } if (!IsRunningOnAppVeyor) { throw new CakeException("The current build is not running on AppVeyor."); } var baseUri = _environment.GetEnvironmentVariable("APPVEYOR_URL").TrimEnd('/'); if (string.IsNullOrWhiteSpace(baseUri)) { throw new CakeException("Failed to get AppVeyor API url."); } var url = string.Format(CultureInfo.InvariantCulture, "{0}/api/testresults/{1}/{2}", baseUri, resultsType, Environment.JobId); using (var stream = File.OpenRead(path.FullPath)) using (var client = new HttpClient()) { client.PostAsync(url, new StreamContent(stream)).Wait(); } }
/// <summary> /// Uploads test results XML file to AppVeyor. Results type can be one of the following: mstest, xunit, nunit, nunit3, junit. /// </summary> /// <param name="path">The file path of the test results XML to upload.</param> /// <param name="resultsType">The results type. Can be mstest, xunit, nunit, nunit3 or junit.</param> public void UploadTestResults(FilePath path, AppVeyorTestResultsType resultsType) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (!IsRunningOnAppVeyor) { throw new CakeException("The current build is not running on AppVeyor."); } var baseUri = _environment.GetEnvironmentVariable("APPVEYOR_URL").TrimEnd('/'); if (string.IsNullOrWhiteSpace(baseUri)) { throw new CakeException("Failed to get AppVeyor API url."); } var url = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/api/testresults/{1}/{2}", baseUri, resultsType, Environment.JobId).ToLowerInvariant()); _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Uploading [{0}] to [{1}]", path.FullPath, url); Task.Run(async() => { using (var client = new HttpClient()) { var response = await client.UploadFileAsync(url, path.FullPath, "text/xml"); var content = await response.Content.ReadAsStringAsync(); _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Server response [{0}:{1}]:\n\r{2}", response.StatusCode, response.ReasonPhrase, content); } }).Wait(); }
public void RunNUnitTests(AppVeyorTestResultsType testType, string whereFilter = null) { var assemblies = _globber.GetFiles("./**/bin/" + Configuration + "/*.Tests.dll").ToList(); assemblies = assemblies.Union(_globber.GetFiles("./**/bin/" + Configuration + "/*.Test.dll")).ToList(); if (assemblies.Count == 0) { _log.Error("No Tests Found"); return; } foreach (var file in assemblies) { _log.Verbose($"Using test asembly:{file.FullPath}"); } //NUnit test runners output if a file is given. Should only output if NoResults is false...but it doesnt.. var testResultsFile = IsInteractiveBuild ? null : new FilePath("./TestResult.xml"); try { if (testType == AppVeyorTestResultsType.NUnit3) { NUnit3Test(assemblies, testResultsFile, whereFilter); } else { NUnit2Test(assemblies, testResultsFile, whereFilter); } if (IsAppVeyor) { _appVeyorProvider.AddInformationalMessage("Tests Passed"); } } catch { if (IsAppVeyor) { _appVeyorProvider.AddErrorMessage("Tests Failed"); } throw; } finally { if (IsAppVeyor) { _appVeyorProvider.UploadTestResults(testResultsFile, testType); } } }