Friday, April 22, 2016

Make UnitTest Report Using HTMLTestRunner

I am a big fan of Python, and I am a big fan of TDD (Test Driven Development). The problem that I face for team development was that it is quite difficult to communicate the testing results to the team, because the results are in terminal so only us and God know :D

Fortunately, somebody out there know my problem and create this amazing This tool is very handy and very easy to use. It almost feels like you don't need to do anything. OK, here's one example on how we use HTMLTestRunner. Ah, forget it. Download from this website, and put somewhere in your computer. Say in this example, I put in ~/Downloads/HTMLTestRunner folder

import unittest
import sys
_path = r"Downloads/HTMLTestRunner"
import HTMLTestRunner

class TestDemo(unittest.TestCase):
    def testA(self):
        assert True
    def testB(self):
        assert False

class TestDemo2(unittest.TestCase):
    def testC(self):
        assert True
    def testD(self):
        assert True

def suite():
    suite = unittest.TestSuite()
    # TestDemo
    # TestDemo2

    return suite

if __name__ == "__main__":
    suite = suite()
    output = open("results.html", 'w')
    runner = HTMLTestRunner.HTMLTestRunner(stream=output, title='Test Report', description='This is a test')

After you run it, boom... you will get a beautiful and informative report in html file. Here is the results in my example:

Thursday, April 21, 2016

Import Python Script to SikuliX

When we need to import python script into sikulix workspace, here is one of the way to do:

1. Import sys
2. Append the path to the script into sys.path
3. Import your python script

Here is an example

import sys


import HTMLTestRunner

However, it has some limitations. You should refer to this document:

Monday, April 11, 2016

Get Operating System used by SikuliX

If we write SikuliX code to check app on different operating system, we may need to define characteristic for each OS (e.g. image library or specific code). To check it, we can use built-in SikuliX script. Following is an example of OS checking

if Settings.isWindows():
    print "I am running on Windows"
elif Settings.isLinux():
    print "I am running on Linux"
elif Settings.isMac():
    print "I am running on Mac"

That's it. Hope it helps.

Thursday, April 7, 2016

Make vi appearance to be "real programming IDE"

"why not just use IDE or something like gedit?"

I had that question long ago and that made me stick to GEdit and other IDEs. However, when I have to do some works on files in server, I just realise that I have to familiarise myself to command-based editor. And, that's the beginning for me to know vi.

When I open it, the appearance is so boring. No line number, no syntax color. So, I decided to make at least that two things to make vi to be IDE like. Hahaha... Here's what I did:

$ vi ~/.vimrc

then type these lines in vimrc file

set number 

syntax on

colorscheme desert

set number will add line number on the left part of vi

syntax on will add colour of the syntax

colorscheme desert will set the colour scheme to be "desert"

That's it. I hope I can add some more customization of vi in the future. I feel that I am falling in love for the second time. Oh, vi... I love you.