Windows Vista Forums

Embedded testing method in scripts?
  1. #1


    Mike Schinkel Guest

    Embedded testing method in scripts?

    Is there a standard way to embed a testing method within a script?
    What I'm looking for is something similar to the idiom you seen in
    Python at the bottom of .py files to include a component for testing?
    In Python it is often used for creating an entry point for something
    that might otherwise be used as a function library, but it can also be
    used for testing.

    if __name__ == '__main__':
    Do_something()

    I'm trying to implement something like this but it is very verbose and
    feels kludgy.

    -Mike




      My System SpecsSystem Spec

  2. #2


    hecks@hotmail.co.uk Guest

    Re: Embedded testing method in scripts?

    On Jun 9, 3:18 am, Mike Schinkel <mikeschin...@gmail.com> wrote:
    > Is there a standard way to embed a testing method within a script?
    > What I'm looking for is something similar to the idiom you seen in
    > Python at the bottom of .py files to include a component for testing?
    > In Python it is often used for creating an entry point for something
    > that might otherwise be used as a function library, but it can also be
    > used for testing.
    >
    > if __name__ == '__main__':
    > Do_something()
    >
    > I'm trying to implement something like this but it is very verbose and
    > feels kludgy.
    >
    > -Mike


    I suppose it depends on the script. If it's basically expressed as
    a series of functions, it's pretty easy to call them individually by
    adding this entry point immediately below the last function statement:

    if ($args[0] -ne $null) { &$args[0] ; exit }

    Then test individual functions like so: foo-bar.ps1 {function1 arg1
    arg2 etc}. Or make a special test function that calls a set of other
    functions in a specific order, etc. I've found that in some cases,
    it's very handy to write whole scripts as linked functions because of
    the flexibility it gives in situations like this.

    Otherwise there's the -whatif switch.

    -Hecks



      My System SpecsSystem Spec

Embedded testing method in scripts? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
run .cmd scripts on remote machine (automating the MOSS install via scripts) Zoran PowerShell 1 21 Jul 2009
testing server side scripts on Vista aa Vista General 5 01 Jul 2009
MoveNext() method not covered by unit testing? Steve .NET General 1 18 Jan 2009
Method invocation failed because [System.String] doesn't contain a method B Williams PowerShell 0 31 Mar 2008
Updated: PowerShell Scripts for Testing Adam Geras PowerShell 2 07 Feb 2007