def testNonEmpty(self): error = "<error>&</error>" results = [ runcppunit.Result("Foo", "Bar", None), runcppunit.Result("Foo", "Baz", error) ] out = cStringIO.StringIO() runcppunit.writeJUnitXml(out, "foo_test", 0.5, "", "", results) dom = xml.dom.minidom.parseString(out.getvalue()) self.assertEquals(dom.firstChild.getAttribute("tests"), "2") self.assertEquals(dom.firstChild.getAttribute("failures"), "1") tests = dom.getElementsByTagName("testcase") self.assertEquals(2, len(tests)) self.assertEquals("foo_test.Foo", tests[0].getAttribute("classname")) self.assertEquals("Bar", tests[0].getAttribute("name")) self.assertEquals("0.000", tests[0].getAttribute("time")) self.assertEquals(0, tests[0].childNodes.length) self.assertEquals("foo_test.Foo", tests[1].getAttribute("classname")) self.assertEquals("Baz", tests[1].getAttribute("name")) self.assertEquals("0.000", tests[1].getAttribute("time")) self.assertEquals(1, tests[1].childNodes.length) self.assertEquals("failure", tests[1].firstChild.tagName) self.assertEquals("null", tests[1].firstChild.getAttribute("message")) self.assertEquals("junit.framework.AssertionFailedError", tests[1].firstChild.getAttribute("type")) self.assertEquals(error, tests[1].firstChild.firstChild.data)
def testNonEmpty(self): error = "<error>&</error>" results = [runcppunit.Result("Foo", "Bar", None), runcppunit.Result("Foo", "Baz", error)] out = cStringIO.StringIO() runcppunit.writeJUnitXml(out, "foo_test", 0.5, "", "", results) dom = xml.dom.minidom.parseString(out.getvalue()) self.assertEquals(dom.firstChild.getAttribute("tests"), "2") self.assertEquals(dom.firstChild.getAttribute("failures"), "1") tests = dom.getElementsByTagName("testcase") self.assertEquals(2, len(tests)) self.assertEquals("foo_test.Foo", tests[0].getAttribute("classname")) self.assertEquals("Bar", tests[0].getAttribute("name")) self.assertEquals("0.000", tests[0].getAttribute("time")) self.assertEquals(0, tests[0].childNodes.length) self.assertEquals("foo_test.Foo", tests[1].getAttribute("classname")) self.assertEquals("Baz", tests[1].getAttribute("name")) self.assertEquals("0.000", tests[1].getAttribute("time")) self.assertEquals(1, tests[1].childNodes.length) self.assertEquals("failure", tests[1].firstChild.tagName) self.assertEquals("null", tests[1].firstChild.getAttribute("message")) self.assertEquals("junit.framework.AssertionFailedError", tests[1].firstChild.getAttribute("type")) self.assertEquals(error, tests[1].firstChild.firstChild.data)
def testEmpty(self): #~ results = [runcppunit.Result("Foo", "Bar", True), runcppunit.Result("Foo", "Bar", False)] text = '<?xml version="1.0"?><hello>world&bar</hello>' out = cStringIO.StringIO() runcppunit.writeJUnitXml(out, "foo_test", 0.5, text, text, []) dom = xml.dom.minidom.parseString(out.getvalue()) self.assertEquals(dom.firstChild.getAttribute("name"), "foo_test") self.assertEquals(dom.firstChild.getAttribute("tests"), "0") self.assertEquals(dom.firstChild.getAttribute("failures"), "0") self.assertEquals(dom.firstChild.getAttribute("time"), "0.500") timestamp = dom.firstChild.getAttribute("timestamp") tuple_time = time.strptime(timestamp, "%Y-%m-%dT%H:%M:%S") stdout = dom.getElementsByTagName("system-out")[0].firstChild.data stderr = dom.getElementsByTagName("system-err")[0].firstChild.data self.assertEquals(text, stderr)