Use Ruby's Unit-testing functionality in Sketchup
-
So I copied the test and underlying folders from my Ruby 1.8 installation to the Plugins folder of Sketchup.
I bumped into another load error, so I also copied the optparse.rb file to the Plugins folder. Now my code snippet is loading fine. I'll come back with more news, once I've done some real testing.L.
-
@lbaeyens said:
You could either require that your plugin users install the latest version of Ruby on their computer
hmm.. I don't think that sounds like a good solution. As a user I'd rather not have to install a full separate Ruby installation.
-
I don't know why on Mac SU comes with the full Ruby set while on PC only the "core" Ruby components are deployed.
-
Yea, there are many questionmarks regarding the SU Ruby implementation...
-
@lbaeyens said:
I don't know why on Mac SU comes with the full Ruby set while on PC only the "core" Ruby components are deployed.
because OSX, not SU, has Ruby preinstalled by default (among other nice things).
-
I'm interested in learning how unit testing can improve the development process for plugins. I've never felt I needed it, but I can't really justify that feeling because I really don't know what unit testing is all about.
My plugins are simple and straight-forward. I am making an assumption that testing is designed more for software that is too large to understand as a whole, and so it is divided into smaller pieces (units.) Then the tests make sure you're smaller units don't break as you work on the other parts.
-
I got it working! thanks to Scott (the author of the slide deck remember)
the issue was that the stdout which is the standard output stream used by the TestRunner is not supported in SU, so you need to implement a SU specific output stream SketchupConsoleOutput in this case
a second issue that had to be resolved was the reference to Test::Unit::UI::NORMAL.
but now it's up and running. copy the code into a .rb file and give it a try.Test driven SU, here we come!
require 'test/unit/ui/console/testrunner'
require 'test/unit'
require 'sketchup'
Sketchup.send_action "showRubyPanel:"module Sketchup
class Model
def dumpr
return true
end
end
endclass SketchupConsoleOutput
def puts s
print s.to_s + "\n"
end
def write s
print s
end
def flush
#nop
# The testrunner expects to be able to call this method on the supplied io object.
end
endclass ModelDumpTest < Test::Unit::TestCase
def test_dumpexistingmodel
assert_equal true, Sketchup.active_model.dumpr
end
enddef runTests
runner = Test::Unit::UI::Console::TestRunner.new(ModelDumpTest, Test::Unit::UI::NORMAL, SketchupConsoleOutput.new)
runner.start
endUI.menu("PlugIns").add_item("TestRunner") { runTests }
-
test driven development for sketchup plugins
well, I come out of the classic software development space and apply TDD for the last 10 years. when I started experimenting with SU plugin development, I started without TDD, but after a while I felt like developing "naked". once you're used to the TDD way, you won't go back to the non TDD way. and Ruby has embedded TDD capability, so no excuse!
I'm glad I got it up and running, I'll keep you tuned on my TDD adventures in SU Ruby -
You can also start sketchup from the command line as follows:
$ sketchup.exe > log.txt
And then output goes to the file as long as you do not open the Ruby Console. The Ruby Console slows SU down and is less convenient when there is a lot of output.
So is the example code you posted an actual test you would write, or is it for testing the setup?
-
the code snippet is not an actual test, but just to prove it works. now the real work starts. thanks for the hint on directing the SU output.
Advertisement