Markus
Markus

Reputation: 215

NUnit Test on Jenkins fail (nunit xml result file is empty )

I recently started to build my C# Projects on a Jenkins build server.

But recently i had the problem that the reported NUnit xml is empty (the file is created but has no content.)

Console output is as follows

Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information [WARNINGS] Parsing warnings in console log with parser MSBuild [WARNINGS] Computing warning deltas based on reference build #288 Recording NUnit tests results ERROR: Step ‘Publish NUnit test result report’ aborted due to exception: hudson.util.IOException2: Could not transform the NUnit report. Please report this issue to the plugin author at hudson.plugins.nunit.NUnitArchiver.invoke(NUnitArchiver.java:65) at hudson.plugins.nunit.NUnitArchiver.invoke(NUnitArchiver.java:26) at hudson.FilePath.act(FilePath.java:990) at hudson.FilePath.act(FilePath.java:968) at hudson.plugins.nunit.NUnitPublisher.perform(NUnitPublisher.java:145) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723) at hudson.model.Build$BuildExecution.post2(Build.java:185) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668

i know that the problem are probably the leaked file descriptors, but i am not really sure how to fix that.

the NUnit tests are executed with a powershell script, that grabs all necessary dlls

powershell script:

param(
[string] $sourceDirectory = "./trunk/TestProjects/"
, $fileFilters = @("*UnitTest*.dll")
, [string]$filterText = "*\bin*"
)

#script that executes all unit tests available.


Write-Host "Source: $sourceDirectory"
Write-Host "File Filters: $fileFilters"
Write-Host "Filter Text: $filterText"

$cFiles = ""
$nUnitExecutable = "C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe"

# look through all subdirectories of the source folder and get any unit test assemblies. To avoid duplicates, only use the assemblies in the bin folder
[array]$files = get-childitem $sourceDirectory -include $fileFilters -recurse | select -expand FullName | where {$_ -like $filterText}

foreach ($file in $files)
{
    $cFiles = $cFiles + '"' + $file + '"' + " "
}

# set all arguments and execute the unit console
$argumentList = @("$cFiles", "--result=nunit-result.xml;format=nunit2","--framework=net-4.5","--process=Single")

$unitTestProcess = start-process -filepath $nUnitExecutable -argumentlist $argumentList -nonewwindow
echo "$nUnitExecutable $argumentList"


$exitCode = $unitTestProcess.ExitCode

exit $exitCode

this problem only happens if the script is executed via jenkins

#######################UPDATE

after some investigation i found out that his only happens when i add 1 testcase in which wpf controls are created by invoking them on the UI thread.

        [Test Apartment(ApartmentState.STA) RunInApplicationDomain]
    public void CheckPluginModel()
    {
        var app = Application.Current ?? new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown };
        PluginModel model = new PluginModel();

        var task= model.LoadPluginsFromPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));


        RunApplication(() => task.IsCompleted);


        Assert.That(model.AvailablePluginControls.Count, Is.EqualTo(1));
        Assert.That(model.Workflows.Count, Is.EqualTo(1));
        Console.WriteLine("Plugin model check finished");

    }

RunApplication:

        /// <summary>
    /// Runs the application. as long as abortCriteria returns false
    /// </summary>
    /// <param name="abortCriteria">The abort criteria.</param>
    private void RunApplication(Func<bool> abortCriteria, int duetime = 100, int period=100)
    {

        Console.WriteLine("Application started");
        System.Threading.Timer timer = null;
        timer = new Timer((obj) =>
        {
            if (abortCriteria.Invoke())
            {
                Application.Current.Dispatcher.Invoke(() => Application.Current.Shutdown());
                timer.Dispose();

            }
        }, null, duetime, period); 

        Application.Current.Run();

        Console.WriteLine("Application stopped");
    }

All GUI elements are created

await Application.Current.Dispatcher.BeginInvoke(new Action(() => AvailablePluginControls.Add((APControl)Activator.CreateInstance(item))),null);

Upvotes: 0

Views: 2383

Answers (2)

Markus
Markus

Reputation: 215

The problem was as followed:

The unit tests are executed via the powershell script. The powershell start process does not wait untill the process has finished. This causes the problem that a child process is not finished.

in order for start-process to wait until the process has finished, the flag -Wait has to be added.

Upvotes: 1

mustafa savaşcı
mustafa savaşcı

Reputation: 11

Nunit Plugin in Jenkins is not support Nunit 3 xml format. I also the similar problem on Jenkins. I used to convert Nunit 3 result format to Nunit 2 format.

"C:\NUnit 3.5.0\nunit3-console.exe" /result:\MyApplication.xml;format=nunit2 "D:\Jenkins\workspace\MyApplication.Tests.dll"

Upvotes: 1

Related Questions