Examples of unit tests in ruby for sketchup plugins
-
Hello,
Are there any examples of unit tests in ruby for sketchup plugins?Thanks.
-
I would be also interested to see some strategies shared and learn from how other developers do unit tests.
When experimenting with unit tests I learned that it is important to distinguish between "unit tests" (tests an individual method's output for the range of possible input) and "integration tests" (tests the end result of what a plugin and all its components/methods does after being launched).
Also test only your interfaces (think of "your API") and not technical implementations that you might change somewhen (@@variables
).Simple ruby methods are often so obvious that writing unit tests for them distracts you from the real important things that are more likely to break. And the integration is hard to test and error-prone, because
- webdialogs are often asynchronous and need user input (ie. your test runs to the end without receiving a result from the dialog)
- webdialogs have JavaScript code. While there are JS unit test frameworks, your code might depend on the Ruby side which makes it complicated.
- trying to automate the webdialog by injecting JavaScript leads to hacks, and you have to fix the test more often than the real code you are trying to test.
- you cannot make private JS functions public
You can make private Ruby methods public with (for example):
def setup # Make all private methods public. (MyPlugin.private_instance_methods - Object.private_instance_methods).each{ |method| MyPlugin.instance_eval{ public method.to_sym } } end
Attached is a (incomplete) extract from one of my unit tests.
-
@nits4 said:
Hello,
Are there any examples of unit tests in ruby for sketchup plugins?Thanks.
There is TestUp with a framework. But it doesn't work with Ruby 2.0 in SU2014. It used some old and custom frameworks that aren't supported any more.
https://github.com/SketchUp/sketchup-developer-toolsInternally we've begun on a new framework, but it's not something that's even remotely ready for distribution.
Advertisement