How to do TDD and unit testing in powershell?

后端 未结 6 526
遥遥无期
遥遥无期 2020-12-02 08:45

With MS ramming powershell into all new server products, I\'m starting to (reluctantly) think I need to take it seriously. Part of \"taking it seriously\" is TDD. Have you f

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 09:00

    I think you're asking about "testing strategies" instead of TDD specifically, so I'll answer both questions.

    The bulk of your work in PowerShell will be integrating a bunch of disparate systems via cmdlets and object pipes. If you want to be confident your PowerShell scripts work, put as much effort as possible into building a perfect staging environment, so as to test all these systems as accurately as possible.

    Running your scripts in a perfect staging environment will be infinitely more valuable than "fleshing out your design" via TDD or "testing your code's intent" with after-the-fact unit tests.

    Small notes that may help:

    • The -whatif switch exists on built-in cmdlets. Also I just found out you can do this as well: -whatif:$someBool - you'll know when you need it.
    • The ISE coming in V2 has a debugger. Sweet.
    • You can always code up a custom cmdlet in C# and do whatever you want there.

提交回复
热议问题