There's some way to "force error" or "failure" for XMLTestRunner?

Asked by Akissel Donner da Silva

Hi. Good evening for everyone.

I'm working with Sikuli + XMLTestRunner on a larger task. In one part of the code that I write on Sikule IDE, I have an IF, and, inside this if I want to "force" an error or failure, because I want to the the info of fail in XMLTestRunner.

I have been trying for 12 hours diferents kinds of codes or style of codes and nothing work's fine.

I see this page http://doc.sikuli.org/faq/020-unit-test.html where they talk about junit.framework.TestCase, and, inside this framework I find a class named "TestResult" with methods addError and addFailure that will be work a lot fine for me, but I don't undestant how to "declare" it in my code.

Let's take a look about my code:
class C1Cars(unittest.TestCase):
    def C1_CT1Ford(self):
        setFindFailedHandler(handler)
        wait(Pattern("1541773517913.png").similar(0.63),60000)
        find("1543577993389.png") #this pic will not be found, and the handler will be called.
        click("1541772230536.png")
        click("1541772263254.png")
        type(' sikulix')
        wait("1541772336503.png",100)
        if(handlerchamado>0): #inside handler definition, we increase this var
            ### HERE I WANT TO RETURN AN ERROR ####
            ### SO THE METHOD WILL BE THERE ####
        else:
            ### HERE THE TEST WILL END WITHOUT RETURN ANY ERROR

def suite():
    suite = unittest.TestSuite()

    suite.addTest(C1Cars('C1_CT1Ford'))
    #suite.addTest(TestDemo('testB'))

    return suite

Someone can help me?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roman Podolyan (podolyan-roman) said :
#1

1) I think you may try to use "assert" instead of if-else, like
====
assert handlerchamado<=0
====

If statement under assert is correct, script goes as nothing happened, but if assert condition is failed, script should raise an error which should fail the test.

( see http://www.jython.org/jythonbook/en/1.0/ExceptionHandlingDebug.html for assert examples )

2) They say XMLTestRunner is unmaintained ( https://github.com/srittau/xmltestrunner )

Revision history for this message
RaiMan (raimund-hocke) said :
#2

see comment #1

Can you help with this problem?

Provide an answer of your own, or ask Akissel Donner da Silva for more information if necessary.

To post a message you must log in.