Question

I have console application which launches some tests during build.

<exec>
   <executable>Tests.exe</executable>
   <baseDirectory>Q:\Software\Platform\</baseDirectory>
   <buildTimeoutSeconds>100</buildTimeoutSeconds>
</exec>

And i want to redirect it's output to text file and then include it in my report file. I tried the following approach to redirect output to NativeUtilsTestReport.txt (like in command line somefile.exe > file.txt):

<exec>
   <executable>Tests.exe</executable>
   <baseDirectory>Q:\Software\Platform\</baseDirectory>
   <buildArgs> > NativeUtilsTestReport.txt</buildArgs>
   <buildTimeoutSeconds>100</buildTimeoutSeconds>
</exec>

but it doesn't seem to work. Tests works fine, but there is no text file with report.

How can i get output from this "exec" section?

Was it helpful?

Solution 3

I ended up with writing my own ExecutableTask for cruise control, which reads output from CCnet IIntegrationResult.TaskResults and writes it to file. Application writes to output plain text, but CCnet transforms it to following XML:

<buildresults>
<task><buildArgs />
   <buildTimeoutSeconds>100</buildTimeoutSeconds>
   <baseDirectory>Q:\software\Platform\</baseDirectory>
   <dynamicValues />
   <environment />
   <executable>NativeUtils.Tests.exe</executable>
   <OutputFilePath>Q:\software\NativeUtilsTestReport.txt</OutputFilePath>
   <priority>Normal</priority>
   <successExitCodes />
</task>
      <message>Running 50 test cases...</message>
</buildresults>


<buildresults>
    <task><buildArgs />
    <buildTimeoutSeconds>100</buildTimeoutSeconds>
    <baseDirectory>Q:\software\Platform\</baseDirectory>
    <dynamicValues />
    <environment />
    <executable>NativeUtils.Tests.exe</executable>
    <OutputFilePath>Q:\software\NativeUtilsTestReport.txt</OutputFilePath>
    <priority>Normal</priority>
    <successExitCodes />
</task>
  <message level="Error">*** No errors detected</message>
</buildresults>

Here is code:

[ReflectorType("execWithOutput")]
class ExecutableTestTask:ExecutableTask
{
    [ReflectorProperty("OutputFilePath", Required = false)]
    public string OutputFilePath { get; set; }

    protected override bool Execute(ThoughtWorks.CruiseControl.Core.IIntegrationResult result)
    {
        bool rez = base.Execute(result);

        if (!string.IsNullOrEmpty(OutputFilePath))
        {
            using (FileStream fs = new FileStream(OutputFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    var lastIndex = result.TaskResults.Count-1;
                    // read output from last executed task
                    var output = ((ProcessTaskResult)result.TaskResults[lastIndex]).Data;

                    string parsedOutput = readMessagesFromXml(output);

                    sw.Write(parsedOutput);
                }
            }
        }
        return rez;
    }

    // parse xml
    private string readMessagesFromXml(string xml)
    {
        StringBuilder sb = new StringBuilder();

        try
        {
            // wrap output to into single root node
            var xmlWithRootNode = string.Format("<report>{0}</report>", xml);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlWithRootNode);
            var nodes = doc.SelectNodes("//report/buildresults/message");

            if (nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    sb.AppendLine("<div>" + node.InnerText + "</div>");
                }
            }
            else
            {
                sb.AppendLine("Xml output does not contain valid data or there are no messages");
            }
        }
        catch (Exception ex)
        {
            sb.AppendLine("Exception during parsing XML task output. "+ex.ToString());
        }

        return sb.ToString();
    }

}

And then i call it during build:

<execWithOutput>
        <executable>NativeUtils.Tests.exe</executable>
        <baseDirectory>Q:\software\Platform\</baseDirectory>
        <OutputFilePath>Q:\software\NativeUtilsTestReport.txt</OutputFilePath>
        <buildTimeoutSeconds>100</buildTimeoutSeconds>
</execWithOutput>

OTHER TIPS

You cannot use < or > in xml. I am able to redirect output like this.

<exec>
   <executable>Tests.exe</executable>
   <baseDirectory>Q:\Software\Platform\</baseDirectory>
   <buildArgs> &gt; NativeUtilsTestReport.txt</buildArgs>
   <buildTimeoutSeconds>100</buildTimeoutSeconds>
</exec>

Then you can include the output into your log using the merge task.

<merge>
  <files>
    <file>NativeUtilsTestReport.txt</file>
  </files>
</merge>

I would also recommend that you save your output to the artifact directory.

$(ArtifactDirectory)\NativeUtilsTestReport.txt

I'll have to use a metaphor.

NUnit it a testing program.

So when you run

nunit-console.exe SomeDll.dll "c:\somefolder\NUnitTest_RESULTS.xml"

The console app itself will outsome some XML....with a specific name.

So even if get an output xml file, this doesn't do anything for CC.NET.

You use a CC.NET file-merge task to "suck up" the NUnitTest_RESULTS.xml into the "ThisBuildCCNet_SuperDuperXmlFile.xml". (That's not the name, that is the concept).

And that doesn't do anything really.

CC.NET has "NUnit" installed, which is a link to an xsl file.

So after NUnitTest_RESULTS.xml is created AND NUnitTest_RESULTS.xml is "sucked up" into the super-duper.xml file AND you have the NUnit-Xsl enabled, when you click on the NUnit menu item (on the webpage of your project), CC.NET will take the nunit.xsl and apply it to the xml that now exists in the super-duper.xml file. Aka, a basic xsl-xml transformation.

So to your question, if you want your console app to run tests, it should be able to output XML to a file. If it can't do that, then you're d3ad in the water.

If you get xml, then you have to use the file-merge task to "suck it up", and you have to author or find an xsl file to transform it.

.......

EDIT

If you cannot generate xml or hmtl (via htmlReportPlugin )

then I suggest this article:

http://testquest.docs.bsquare.com/Integration_Samples_CCNet/Configuring_CCNet_dashboard_to_Display_Test_Execution_Logs.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top