Testing on the client side

Inspired by this post I decided to give a try to testing the client side.

I thought I would get the test to do a bunch of button.raise_event('click') and check that the controls have the expected values. I copied as diligently as possible from the above mentioned post, but I can’t get it to work. When I run the test I get this error:

KeyError: __bases__
at src/lib/unittest/__init__.py, line 228 column 8
  called from TestSuite, line 17
  called from Form1, line 15
  called from Form1, line 15

What am I doing wrong?

Here is the little test testing app https://anvil.works/ide#clone:KKJPVDOR34POIUMV=B3RUSZJV4KSBMF25NTZ5H7X7

1 Like

Hrm - looks like Skulpt’s unittest support is less flexible than we’d like. For now, you can work around it by instantiating a TestCase class and calling main() on it, like so:

# This is a workaround that uses internal details of client-side "unittest":
tc = MyTestCase()
tc.main()
# You may want to read tc.numPassed and tc.numFailed at this point
1 Like

Thanks, it works!

I modified the app for anybody that wants to use it.

The app has a form with two buttons. The first button is the one that is tested, the second starts the test.

The test suite contains two tests, one to make sure the button does the correct job and another that waits for something to happen. In this case it waits for a timer to set the label_1.text to a value greater than 10.

If the test starts less than 5 seconds after starting the app the second test will fail, otherwise it will succeed.

Is it documented anywhere what Skulpt’s unittest functionality is? I’m new to unittest so I may just be making an obvious mistake, but when I try to test out setupModule() and setUpClass(), and corresponding teardowns (following this guide), they don’t seem to get called.

Edit: I’m thinking maybe this indicates what is available: https://github.com/skulpt/skulpt/blob/master/src/lib/unittest/__init__.py