From: Alex Young Date: 2007-09-05T18:24:18+09:00 Subject: Re: Embedded vs. Non-embedded Tests Stefan Rusterholz wrote: > Peter Cooper wrote: >> And if you get onto, say, Formula 1 cars.. some "repairs" can even take >> place on the road and the telemetry provides almost as much info to the >> engineers while the car is running out on the track as they can get in >> the >> garage. I've always wondered if/how to make software as easy to diagnose >> with real-time telemetry and the ability to make changes to a running >> program's parameters.. > > Take a look at Eiffels Design By Contract. I'm a huge fan of it. Allows > you to move most testing code into the contract, the unit tests are then > merely running your code with contracts enabled. > For an idea on how that works, take a look at the movies with "Design by > Contract" in the title here: http://eiffel.com/developers/presentations/ > Would be a very nice feature if ruby had that, even though I'd introduce > additional syntax and I've no idea how to integrate it nicely. Allow me to shamelessly copy and paste from an old post of mine: $ cat testable.rb module Test; module Unit; class TestCase; end; end; end module Testable def test_case(&block) Class.new(Test::Unit::TestCase).module_eval &block end end $ cat builtin_tests.rb require 'testable' class MyWorkingClass extend Testable def foo(a,b) return a+b end test_case { def test_foo_null assert_equal 2, MyWorkingClass.new.foo(1,1) end } end if __FILE__ == $0 puts MyWorkingClass.new.foo(1,1) end $ ruby builtin_tests.rb 2 $ testrb builtin_tests.rb Loaded suite builtin_tests.rb Started . Finished in 0.00095 seconds. 1 tests, 1 assertions, 0 failures, 0 errors $ Something like that? -- Alex