Scripted tests and package exports?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Scripted tests and package exports?

Griff-2
Here is a scenario for which I would like advice:

Suppose I have got a system composed of these packages:
Business Logic
Tests
GUI

How would I go about writing a Smalltalk script to run in a workspace
that would:

1. Run the tests.
2. If the tests pass, export the packages to some location.
3. Optionally, export them even if the tests fail.


Reply | Threaded
Open this post in threaded view
|

Re: Scripted tests and package exports?

Schwab,Wilhelm K
Griff wrote:

> Here is a scenario for which I would like advice:
>
> Suppose I have got a system composed of these packages:
> Business Logic
> Tests
> GUI
>
> How would I go about writing a Smalltalk script to run in a workspace
> that would:
>
> 1. Run the tests.
> 2. If the tests pass, export the packages to some location.
> 3. Optionally, export them even if the tests fail.

The methods below might help.  I use #prod: to put test-running comments
in most of my test cases, something like

testSomething
   "
     SomethingTestCase prod:#testSomething
   "
   self should:[ etc.].

where #prod: is silent on success and raises a walkback on failure.
When I want to verify that all is well, I use the SUnitBrowser; when I
know there is a problem (or even have good reason to suspect so), I
browse the method and use the #prod: line to skip selection steps and
move directly to a walkback.

Something along the lines of

[
   "tests go here, using variant on #runTestsReferencing:"

   "save"

] on:Error do:[ :e |
   ( MessageBox confirm:'Save packages after test failure(s)?' ) ifTrue:[
         "Save to alternate location"
      ].
   ].
]

Clearly the above is pseudo code, and as such, has never been run, let
alone debugged.  The methods below are part of my arsenal and should
work as advertised (but not warrantied<g>).

Caveat: you might need to use #ifCurtailed: vs. #on:do:.  Start small
and safe and work your way up to what you want.

Have a good one,

Bill


!TestCase class methodsFor!

prod:aSymbol
        "Run the test; do nothing if ok or go to a walkback."

        #wksSafe.
        ( self selector:aSymbol ) runCase.
! !
!TestCase class categoriesFor: #prod:!public! !


!TestCase class methodsFor!

runTestsReferecing:aSelector

                | testCase allTests |


        allTests := Array writeStream.
        self withAllSubclassesDo:[ :aClass |
                allTests nextPutAll:(
                        aClass allTestSelectors collect:[ :each |
                                aClass -> each
                ] ).
        ].

        allTests := allTests contents select:[ :assoc | | aClass selector method |
                aClass := assoc key.
                selector := assoc value.
                method := aClass compiledMethodAt:selector.
                method refersToLiteral:aSelector.
        ].

        allTests do:[ :assoc |
                assoc key prod:assoc value.
        ].
! !
!TestCase class categoriesFor: #runTestsReferecing:!public! !



--
Wilhelm K. Schwab, Ph.D.
[hidden email]