2

I have a rather simple QGIS standalone Python app (2.8.2, Windows 7/64), with some published methods to create different types of geometric primitives (rectangles, circles).

class MyApp(QMainWindow, UI_MyApp)
    def __init__(self, ...)
    def circle(self, x, y, radius)
        ...
        layer.triggerRepaint()
    ...

def run_tests()
    self.circle(...)
    self.circle(...)
    ...

def main()
    ...
    app = QApplication(sys.argv)
    map = MyApp()
    map.show()
    map.raise_()
    app.exec_()
    ...

Now I want to run some automated tests against these methods, in this example circle().

It doesn't matter if I include the test calls inside the class itself (as shown above, e.g. connected with a button in the UI) or kept in a separate module: in both cases all graphics are not drawn until run_tests() finished.

How can I implement a (separate) test module which can call methods of MyApp() application with immediate response after each call and thus acting like an API?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Detlev
  • 4,608
  • 19
  • 26

1 Answers1

3

Have a look at the unittest documentation, it provides great examples for coding your functions so that they are easily testable.

You can then have a look at how to set up your project folder.

And then finally have a look at Best practices in writing automated tests for QGIS plugins

raphael
  • 3,407
  • 23
  • 61