unit test

Asked by Leticia Bermond

Hi,
try a test of the windows calculator but does nothing, I'm doing wrong?

from guide import *
def setUp(self):
    App.open("C://windows/system32/calc.exe")
    wait(2)

def tearDown(self):
    App.close("C://Windows/system32/calc.exe")

def testA(self):
    click("cuatro.PNG")
    click("suma.PNG")
    click("siete.PNG")
    click("igual.PNG")
    assertExist("resultado-1.PNG")
    click("cerrar-1.PNG")

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
RaiMan (raimund-hocke) said :
#1

This kind of test setup has to be run in the Sikuli IDE using the unit test feature (but look faq 1804).
At least the calculator app should open then.

--- but does nothing
... so what exactly does that mean?

--- more comments
- from guide import * should do nothing, since I guess you do not have it
- App.close("C://Windows/system32/calc.exe") should not work: for already opened apps, you need a text from the window's title like App.close("Calculator")
- assertExist("resultado-1.PNG") is no longer supported, use
assert exists("resultado-1.PNG") instead
- assert must be the last statement in a test function, since it ends the function in any case with an assertion exception

Revision history for this message
Leticia Bermond (leticiabermond) said :
#2

Sorry, as a looking faq 1804?

modify the code, but continue to do nothing, ie does not open or run the calculator returns nothing and information.

def setUp(self):
    App.open("C://windows/system32/calc.exe")
    wait(2)

def tearDown(self):
    App.close("Calculadora")

def testA(self):
    click("cuatro.PNG")
    click("suma.PNG")
    click("siete.PNG")
    click("igual.PNG")
    assert exist("resultado-1.PNG")

thanks

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

This script is tested and works on my Win7 (german language)
https://dl.dropbox.com/u/42895525/calculator.sikuli.zip

unzip, open in IDE and have a look.

To run it in unit test mode:
- menu view -> unit test (ctrl-u)
- to run it use the little run button in the right area (unit test)

To run it normally:
uncomment the block at the bottom and run normally (I use SCREEN object as global object, to propagate the variables)

Revision history for this message
Leticia Bermond (leticiabermond) said :
#4

Hi,
I lacked the function calls. Now, as when it returns a wrong value. ie when the unit test is wrong? because sometimes you click on the sign - instead of + and returns -3.

thanks

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

Then it might be necessary, to raise the minimum similarity like

click(Pattern("suma.PNG").similar(0.99))

do not use 1.0 or exact() - buggy.

Revision history for this message
Leticia Bermond (leticiabermond) said :
#6

Thanks, now as I see mistakes in the field of unit tests?

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

????????
I do not understand your question - if it is any ;-)

Revision history for this message
Leticia Bermond (leticiabermond) said :
#8

Sorry, my English is not very good.
When I make a GUI unit test is to detect errors in the software. I need to know where and how I see these errors.

thanks

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

Uuuuups, this is a very basic question.

Using Sikuli, you use the visual approach:
A GUI should produce an area on the screen containing specific images. So a typical test scenario is, to drive the app to the point of interest (which could be done with Sikuli's app, mouse and keyboard features), and then you check, wether a prepared image (how it should be) is at the place where it should be and is the same pixel per pixel.

example:

def testButton(self):
imgButton = "some-wanted-button-image.png"

# drive app to point of interest (could be done in setUp() )

assert exists(imgButton)

This has to be embedded in a standard UnitTestFramework like the basic ones in Python or Java or more feature rich ones like RobotFrameWork and others (see faq 1804)

--- I need to know where and how I see these errors.
Using the basic unit testing features, you have to implement your own reporting on that, which might be combined with capturing screens ore regions containing errors (e.g. HTMLTestRunner with the capture feature).

In cases where I sit before the screen and want to know, what happens and what not, I usually use either the slow motion run mode or the Region.highlight() method, which gives some information, about where, the script is acting currently and might give hints in the case it crashes or goes wrong. But this is not appropriate for unit testing, which normally runs long and unattended.

Can you help with this problem?

Provide an answer of your own, or ask Leticia Bermond for more information if necessary.

To post a message you must log in.