├── gtest_prettify_example.gif ├── README.md ├── gtest_parser.py ├── gtest_template.html └── gtest_example_output.html /gtest_prettify_example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeilZhy/gtest-report-prettify/HEAD/gtest_prettify_example.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gtest-report-prettify 2 | Creates a HTML page from a Google Test JSON or XML report. 3 | 4 | To run: 5 | ```python 6 | python -m gtest_parser PATH_TO_GOOGLE_TEST_JSON_OR_XML_FILE.json/xml 7 | ``` 8 |  9 | -------------------------------------------------------------------------------- /gtest_parser.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sys 3 | from jinja2 import FileSystemLoader, Environment 4 | import xml.etree.ElementTree as ET 5 | 6 | # Constants 7 | TEMPLATE_FILE = "gtest_template.html" 8 | OUTPUT_FILE = "gtest_output.html" 9 | 10 | def process_input(input_file): 11 | """ Processes the input file. 12 | Will return a JSON object to be used by the HTML parser. 13 | If the file is in XML format it will be turned into a JSON object. 14 | """ 15 | 16 | data = None 17 | 18 | with open(input_file) as gtest_json: 19 | if input_file.endswith('.json'): 20 | data = json.load(gtest_json) 21 | elif input_file.endswith('.xml'): 22 | # Need to turn the XML into the same format as the JSON 23 | data = process_xml(gtest_json) 24 | else: 25 | print("Unknown file type.") 26 | return 27 | 28 | return data 29 | 30 | def process_xml(xml): 31 | """ Processes the XML file. 32 | Will return a JSON object that matches that created by GTEST. 33 | """ 34 | 35 | tree = ET.parse(xml) 36 | root = tree.getroot() 37 | overviewName = root.attrib['name'] 38 | overviewTests = int(root.attrib['tests']) 39 | overviewFailed = int(root.attrib['failures']) 40 | overviewDisabled = int(root.attrib['disabled']) 41 | data = { 42 | 'name': overviewName, 43 | 'tests': overviewTests, 44 | 'failures': overviewFailed, 45 | 'disabled': overviewDisabled, 46 | 'testsuites': [] 47 | } 48 | 49 | for child in root: 50 | testSuitename = child.attrib['name'] 51 | totalTests = int(child.attrib['tests']) 52 | failed = int(child.attrib['failures']) 53 | disabled = int(child.attrib['disabled']) 54 | 55 | tempTest = [] 56 | for test in child: 57 | testName = test.attrib['name'] 58 | testTime = test.attrib['time'] 59 | testStatus = test.attrib['status'].upper() 60 | # Getting all of the failure messages 61 | testFailures = [] 62 | for failure in test: 63 | testFailure = failure.attrib['message'] 64 | testFailures.append({ 65 | 'failure': testFailure 66 | }) 67 | 68 | # If there are no failures dont add it to the JSON 69 | if testFailures: 70 | tempTest.append({ 71 | 'name': testName, 72 | 'time': testTime, 73 | 'status': testStatus, 74 | 'failures': testFailures 75 | }) 76 | else: 77 | tempTest.append({ 78 | 'name': testName, 79 | 'status': testStatus, 80 | 'time': testTime 81 | }) 82 | print(tempTest) 83 | tempTestSuite = { 84 | 'name': testSuitename, 85 | 'tests': totalTests, 86 | 'failures': failed, 87 | 'disabled': disabled, 88 | 'testsuite': tempTest 89 | } 90 | data['testsuites'].append(tempTestSuite) 91 | 92 | return data 93 | 94 | def create_html(data): 95 | """ Turns the JSON object into a HTML file. 96 | Will grab the template and render it with our JSON object. 97 | """ 98 | templateLoader = FileSystemLoader(searchpath="./") 99 | templateEnv = Environment(loader=templateLoader) 100 | template = templateEnv.get_template(TEMPLATE_FILE) 101 | 102 | with open(OUTPUT_FILE, "w") as output_html: 103 | output_html.write(template.render(test_overview=data, test_suites=data['testsuites'])) 104 | 105 | if __name__ == "__main__": 106 | json_data = process_input(sys.argv[1]) 107 | create_html(json_data) 108 | -------------------------------------------------------------------------------- /gtest_template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 12 | 13 |{{ "Failure: " + failure.failure }}
151 | {% endfor %} 152 |Failure: c:\users\spencer.robertson\documents\projects\cid\web services testing\webservicestests\webservicestests\test_cases_one.cpp:535 161 | Value of: FALSE 162 | Actual: false 163 | Expected: true
164 | 165 |Failure: c:\users\spencer.robertson\documents\projects\cid\web services testing\webservicestests\webservicestests\test_cases_two.cpp:166 307 | Value of: FALSE 308 | Actual: false 309 | Expected: true
310 | 311 |Failure: c:\users\spencer.robertson\documents\projects\cid\web services testing\webservicestests\webservicestests\test_cases_three.cpp:138 453 | Value of: FALSE 454 | Actual: false 455 | Expected: true
456 | 457 |