IDE: UnitTest: Test Case Results Error

Asked by Vinay Kulkarni

******** recommendation

RaiMan does not recommend to use Sikuli IDE's test feature even for some first steps, since it has too many problems.

see faq 1804

----------------------------------------------------------------

Hello friends, i am using sikuli for testing. when i run test from unti test window, i get error like filename.png not found. eventhough the png file is existing.
i tried with with simple popup window test, still error. can anyone please provide me sample code or else any source from where i get the code.
i tried it running on windows 7, and got errors. I changed .bat file as suggested still error.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

is your code running with a normal IDE run?

What is the reason, you are using the unit test window?

Revision history for this message
Vinay Kulkarni (vinay-s) said :
#2

RaiMan thanks for your concern

Yes my code is running with normal IDE run.

I need to know whether my test has passed or failed. Is it the correct way?

I am starting with simple programs as follows

popup("Hello World!")

above code runs fine in normal IDE run.

I tried this with unit test by putting

def setUp(self):
 setAutoWaitTimeout(1)

def test_calculator(self):
 popup("Hello World!")

def tearDown(self):
 close(self)

Is it necessary to put setUp and tearDown functions? without these the unit test wont return to IDE.

Please provide me some sample code.

My boss wants me to perform automated test on GUI. condition is that it must run at client machine. how can i know where is my application installed. sikuli is totally on screen capture.

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

- no, setUp() and tearDown() are not needed, only if you have some things to do before (setUp) and after (tearDown) each test. Internally the Python unit test module is used (the necessary environment/wrapper) is created internally. So the Python docs apply.

- should give an error
def tearDown(self):
 close(self)

since close is not useable without a referenced object (in this case in Sikuli it is actually mapped to the constant object SCREEN, which is the main screen Screen(0))

- This is a general problem with the current version of this "gimmick" in the IDE: if you get any errors during a test run, that are not catches (e.g. the above syntax error), you will not see it at all and the IDE might hang, so you have to restart.

- generally: If you make any changes to your code, you have to save before running again (the test run is based on the saved version of your script)

I have made a script frame, that can be run either in the normal IDE environment or in the unit test window and allows you, to first gat your script error free, before looking at assertions. (https://files.me.com/rhocke/zpsan6)

--- One more thing:
when playing around, a test case, that does not do real assertions, you should end it with an assert(True), since every test case should end with an assert().

so a minimal test script should look:

def setUp(self):
 pass

def test_calculator(self):
 print "in test_calculator"
 assert(True)

def tearDown(self):
 pass

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

--- you are saying: I changed .bat file as suggested still error.

with rc2, there is no need to change the Sikuli-IDE.bat file.

What did you change?

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

It seems, it should not be just playing around (My boss wants me ....)

So I strongly recommend, to forget the IDE unit test feature (to many restrictions and oddities for professional use) and use the native Jython unit test module and finally run your scripts from command line using
java -jar path-to-sikuli-script.jar path-to-your-testcase.sikuli

It might be necessary, to add some java specific memory options (look at Sikuli-IDE.bat).

Depending on your current development environment it might be worth thinking about using the Java API and JUnit.

-- you ask: how can i know where is my application installed.
A client machine, that needs to run your Sikuli scripts at least needs sikuli-script.jar, the libs directory and it's contents and the system path setup for Sikuli. Currently, there is no Sikuli feature, to pack this together with your script and deploy it on other machines.
So if you need more help on that, you have to tell more about your development and target environments.

Revision history for this message
Vinay Kulkarni (vinay-s) said :
#6

Sikuli is is running fine in Windows 7.

I will run your code and revert.

I hope your resource will work fine. Thanks for your time.

Revision history for this message
Vinay Kulkarni (vinay-s) said :
#7

https://files.me.com/rhocke/zpsan6

This program was not running on Unit test. This code is bit complicated. I am beginner to sikuli. Can you please provide some simple code.

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

-- you say: This program was not running on Unit test. This code is bit complicated
Ok, that might be true for a Sikuli newbee, but not really for someone, who is familiar with Python scripts.
The magic with this example is, that it simulates a unit test run in the normal IDE, which you should do, until you understand what it is doing and it works.

The problem you might have is this line:
 ac = self.ac = App("Rechner")
It was scripted on a german Windows. Exchange the word "Rechner" with the title text of the window of calc.exe.

the last line
weAreInIDE(("testAdd",))

could be changed to run both tests in normal IDE:
weAreInIDE(("testAdd","testTypeNumber"))

if this runs error free, you might switch to the unit test environment.

-- simple code?

the simplest possible code is at the end of comment #2

but you might learn a lot from my example ;-)

-- recommendation
before starting into more complicated things like unit testing with Sikuli, you should learn the basics using the IDE in normal mode. There are many examples around and you have the docs. Looking at some faq's might help too.

And you have to decide, on which level (Python/Jython or Java API) you want to go on, because the approaches and learning needs are totally different.

Revision history for this message
Vinay Kulkarni (vinay-s) said :
#9

I got this error. Pfa file.

Thanks & Regards,
Vinay Kulkarni
Ishnatek Systems & Services Pvt. Ltd.
Contact : +91 8956345939

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of RaiMan
Sent: Wednesday, August 17, 2011 3:21 PM
To: <email address hidden>
Subject: Re: [Question #168233]: IDE: UnitTest: Test Case Results Error

Your question #168233 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/168233

    Status: Open => Answered

RaiMan proposed the following answer:
-- you say: This program was not running on Unit test. This code is bit complicated
Ok, that might be true for a Sikuli newbee, but not really for someone, who is familiar with Python scripts.
The magic with this example is, that it simulates a unit test run in the normal IDE, which you should do, until you understand what it is doing and it works.

The problem you might have is this line:
 ac = self.ac = App("Rechner")
It was scripted on a german Windows. Exchange the word "Rechner" with the title text of the window of calc.exe.

the last line
weAreInIDE(("testAdd",))

could be changed to run both tests in normal IDE:
weAreInIDE(("testAdd","testTypeNumber"))

if this runs error free, you might switch to the unit test environment.

-- simple code?

the simplest possible code is at the end of comment #2

but you might learn a lot from my example ;-)

-- recommendation
before starting into more complicated things like unit testing with Sikuli, you should learn the basics using the IDE in normal mode. There are many examples around and you have the docs. Looking at some faq's might help too.

And you have to decide, on which level (Python/Jython or Java API) you
want to go on, because the approaches and learning needs are totally
different.

--
If this answers your question, please go to the following page to let us
know that it is solved:
https://answers.launchpad.net/sikuli/+question/168233/+confirm?answer_id=7

If you still need help, you can reply to this email or go to the
following page to enter your feedback:
https://answers.launchpad.net/sikuli/+question/168233

You received this question notification because you asked the question.

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

Would be nice if you come back with some feedback, once you have made your experience and decisions.

If solved for the moment: pls. mark it accordingly.

Revision history for this message
Vinay Kulkarni (vinay-s) said :
#11

plz send me your emial address so that i can send you snapshop accordingly.

Revision history for this message
RaiMan (raimund-hocke) said :
#12
Revision history for this message
Mychal Miller (mychaluva) said :
#13

RaiMan, the file that you posted with sample test code no longer exists at the link provided. Is it possible to repost the file?

(dead URL: https://files.me.com/rhocke/zpsan6)

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

@ Mychal
I do not recommend to use Sikuli IDE's test feature even for some first steps, since it has too many problems.

see faq 1804

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

Vinay uses Python's unittest module now.