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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.