03-30-2017 07:31 AM
Hi All,
I have a problem - is there any way of making any unit/functional tests for TestStand sequences? I know that for VIs there are at least several ways of testing, and what with TS?
08-21-2017
11:33 AM
- last edited on
10-11-2024
05:11 PM
by
Content Cleaner
In case you're still interested in this - you could write your own tests using the TestStand API - but realistically, the Sequence Analyzer is the way to go. There are plenty of built in rules, and you can also create your own rules to trigger a warning or an error.
The stand alone analyzer app has a command line interface so this can be automated. The output report is XML, which can be parsed pretty easily or converted to another format with a custom stylesheet. I have a stylesheet that will convert the output to JUnit if anyone is interested.
08-21-2017 12:00 PM
08-21-2017 12:45 PM
I wrote this for TS 2016. It should be very similar for previous versions, but you'll probably need to update the namespaces.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ts="http://www.ni.com/TestStand/16.0.0/PropertyObjectFile" exclude-result-prefixes="ts">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="ts:teststandfileheader/ts:TEOLEDataSource/ts:ReportData/ts:subprops">
<testsuite>
<xsl:attribute name="name">Sequence Analyzer Results</xsl:attribute>
<xsl:attribute name="tests">
<xsl:value-of select="substring-before(substring-after(ts:RulesUsedForAnalysis/ts:value/@ubound,'['),']')+1"/>
</xsl:attribute>
<xsl:for-each select="ts:RulesUsedForAnalysis/ts:value/ts:value/ts:Obj">
<xsl:variable name="ruleId" select="ts:subprops/ts:Id/ts:value"/>
<xsl:variable name="CorrespondingMessage" select="/ts:teststandfileheader/ts:TEOLEDataSource/ts:ReportData/ts:subprops/ts:Messages/ts:value/ts:value/ts:Obj/ts:subprops[ts:RuleId/ts:value = $ruleId]"/>
<xsl:choose>
<xsl:when test="$CorrespondingMessage">
<testcase>
<xsl:attribute name="name">
<xsl:value-of select="ts:subprops/ts:Name/ts:value"/>
</xsl:attribute>
<xsl:attribute name="classname">
<xsl:value-of select="$ruleId"/>
</xsl:attribute>
<xsl:if test="ts:subprops/ts:Severity/ts:value=0">
<error>
<xsl:attribute name="message">
<xsl:value-of select="normalize-space($CorrespondingMessage/ts:Text)"/>
</xsl:attribute>
</error>
</xsl:if>
<xsl:if test="ts:subprops/ts:Severity/ts:value=1">
<failure>
<xsl:attribute name="message">
<xsl:value-of select="normalize-space($CorrespondingMessage/ts:Text)"/>
</xsl:attribute>
</failure>
</xsl:if>
</testcase>
</xsl:when>
<xsl:otherwise>
<testcase>
<xsl:attribute name="name">
<xsl:value-of select="ts:subprops/ts:Name/ts:value"/>
</xsl:attribute>
<xsl:attribute name="classname">
<xsl:value-of select="$ruleId"/>
</xsl:attribute>
</testcase>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</testsuite>
</xsl:template>
</xsl:stylesheet>
You can apply the stylesheet from the command line with MSXSL.exe:
msxsl <path to analyzer report> <path to example stylesheet> -o <path to output xml file>
I'll be posting some related examples in the coming weeks.
Hope this helps!
Trent