sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Examples of unit tests in ruby for sketchup plugins

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 529 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N Offline
      Nits4
      last edited by

      Hello,
      Are there any examples of unit tests in ruby for sketchup plugins?

      Thanks.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        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.


        unit_test_example.rb

        1 Reply Last reply Reply Quote 0
        • tt_suT Offline
          tt_su
          last edited by

          @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-tools

          Internally we've begun on a new framework, but it's not something that's even remotely ready for distribution.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement