I have a test case where the results are saved as csv file. I want to use Jenkins to show the result, and the JUnit format is suitable for me. A part of (more than 1000) results looks like this:
CSV data:
TCName;OverallResult
TC_LIB_001; FAIL
TC_LIB_001; FAIL
FMECA_DIA_034; FAIL
FMECA_DIA_034; PASS
I looked all over the and found a lot of information but still have no clear idea how to convert my CSV file into any format that works to show the results with Jenkins... I don't know what I'm missing.
Tried and tested other XML example files and it worked in Jenkins so I think I'm missing something while converting the CSV file into XML file
So I'm wondering if you guys have any idea?
Edit:
Code import sys
import os
import csv
if len(sys.argv) != 2:
os._exit(1)
path=sys.argv[1] # get folder as a command line argument
os.chdir(path)
csvFiles = [f for f in os.listdir('.') if f.endswith('.csv') or f.endswith('.CSV')]
for csvFile in csvFiles:
xmlFile = csvFile[:-4] + '.xml'
csvData = csv.reader(open(csvFile))
xmlData = open(xmlFile, 'w')
xml_Top= open(xmlFile, 'r')
#xmlData.write('<?xml version="1.0"?>' + "\n")
# there must be only one top-level tag
rn = -1
for rl in csvFile:
rn+=1
xmlData.write('<testsuite tests='+'"'+str(rn)+'"'+'>' + "\n")
print(rn)
rowNum = 0
for row in csvData:
if rowNum == 0:
tags = row
# replace spaces w/ underscores in tag names
for i in range(len(tags)):
tags[i] = tags[i].replace(' ', '_')
else:
xmlData.write('<testcase')
for i in range(len(tags)):
xmlData.write(' ' + 'classname=' + '"'+ row[i].partition(";")[0] +'"'+ ' name=' +'"'+row[i].partition(";")[2] +'" /')
if row[i].partition(";")[2] == " FAIL":
xmlData.write('> ' + ' <failure type="did not passed"> details about failure </failure>'+ "\n")
if row[i].partition(";")[2] != " PASS" and row[i].partition(";")[2] != " FAIL" :
xmlData.write(' ' + ' <failure type="Fatal Error"> details about failure </failure>'+ "\n")
if row[i].partition(";")[2] == " PASS":
xmlData.write('>'+ "\n")
rowNum +=1
xmlData.write('</testsuite>' + "\n")
xmlData.close()
Results(xml file):
<testsuite tests="4">
<testcase classname="TC_LIB_001" name=" FAIL" /> <failure type="did not passed"> details about failure </failure>
<testcase classname="TC_LIB_001" name=" FAIL" /> <failure type="did not passed"> details about failure </failure>
<testcase classname="FMECA_DIA_034" name=" FAIL" /> <failure type="did not passed"> details about failure </failure>
<testcase classname="FMECA_DIA_034" name=" PASS" />
</testsuite>
i was using the simple format from https://stackoverflow.com/a/4925847
Problem: Jenkins returns the test results as passed for the 4 test cases even though I have only 1 passed case and 3 failed
Edit 2: okay solved. my idea was a first solution that shows results in Jenkins. the solution is clearly in need of improvement, depending on requirements.
/> should be closed at the end in case of failure otherwise the failure would be ignored that means that the first 3 lines... hopefully it helps someone in the future :) for more information see https://stackoverflow.com/users/34148/anders-lindahl