-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement unit tests #16
Comments
I'm not sure what we want to test with this, as I've never used it. Who can think of some test cases? |
@sklencar any ideas? |
Essentially the plugin uses the clicked map co-ords and converts them using the xy_to_osgb function. |
Yes. The idea of unit testing is to break tests down into multiple smaller tests, each of which only tests one thing. So, off the top of my head:
Have you had many bugs or problems? If you have, think of tests which would have spotted them. If you can cover most of the code with tests, it will make it easier to handle eg QGIS API changes. The bad news is that my experience of writing QGIS tests is very specific - changing various settings, and ensuring qgis2web exports given code. In other words, my tests always end with comparing an output string to a control. Some of your tests will do that, but others might do something else. We'll see what we come up with. |
Tests above look reasonable. I would like to add: |
Is 5 the current behaviour? I think that should be configurable by checkbox, and default to off - people could lose data. |
Yes, so far it works like that. After opening bbox with info about point a user clicked on, the clipboard is always overwritten. Agree, that it should be configurable. |
OK, first test is there, runs on Travis, and passes. The test itself is the function https://github.com/mtravis/gridref-qgis/blob/master/test/test_gridref.py#L32 To write further tests, add more functions after it, within Hope this is comprehensible. I'll close this issue, but do ask question here if not. |
Right, I'll perhaps try to add one of those markdown checkbox lists to the first post here of possible tests, so we can keep track of what we've done, and add others if we think of them. |
We could run a test to check out the "point out bounds" works. I think also that they want to add this tool to processing toolbox so we should have tests for batch processing but @sklencar will know more about that. |
@mtravis Yes, I got requirement to move the tool to processing toolbox and get rid of the button in the action toolbar. |
Second test implemented and passes. |
Third test implemented and passes. |
Potential issue with proposed test 4, "Changing precision spinner changes precision setting": I don't think "precision" is stored anywhere as a var independent of the spinner - functions read the spinner state directly. That means that you'd only be testing that chaging the spinner changes the spinner, which seems unnecessary. I guess if the plugin is rewritten as a processing algorithm as discussed, and the GUI is therefore decoupled from the functions, then this test will become meaningful. |
Proposed test 5, "Clicking with the tool writes to the clipboard": This is a more complex test, as it will require using |
#16 - nose doesn't handle a line break, evidently
@mtravis So the way this works is that you should write tests in Python, give them a filename starting
test_
, and put them intest
. There are already some there which are provided out of the box by the Plugin Builder. You can then either run those tests individually to check they pass, or usenose
to run them all at once.@akbargumbira (I think) wrote a post describing how to run such tests on Windows, but generally, they only run on Linux/Mac.
Here's an initial list of possible tests, to expand as we think of more:
xy_to_osgb
gives a correct resultxy_to_osgb
outside BNG coverage behaves gracefullyxy_to_osgb
with different precision gives results with the correct precisionThe text was updated successfully, but these errors were encountered: