如何在Powershell中进行TDD和单元测试? [英] How to do TDD and unit testing in powershell?

查看:158
本文介绍了如何在Powershell中进行TDD和单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着MS将Powershell应用于所有新服务器产品中,我开始(勉强地)认为我需要认真对待它. TDD是认真对待"的一部分.您找到用于对Power Shell脚本进行单元测试的好方法了吗?

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 found good methods to unit test power shell scripts?

我从 Geek先生那里找到了嘲笑样本噪音-但是我真的很喜欢 RhinoMocks 之类的东西. Brian Hartsock 有一个来自MS Test的关于Powershell字符串的运行测试的示例.有点骇人听闻,但似乎可行.

I've found samples of mocking from Mr Geek Noise - but I'd really like something like RhinoMocks. Brian Hartsock has a sample of running tests on powershell strings from MS Test. A little hacky, but it seems to work.

我想要的是Powershell TDD体验,就像使用真实"语言一样干净.

What I want is a Powershell TDD experience that is as clean as it is in "real" languages.

更新以进行澄清:

前两个答案试图使我远离测试Powershell.意见很有趣.我不想知道在Powershell中测试是否是个好主意.这是一个主观的问题,应该在其他论坛中提出.我想要一个对Powershell进行单元测试的解决方案.如果您认为这是个坏主意(可能是),请将其视为一个有趣的学术问题.

The first two answers attempt to steer me away from testing Powershell. The opinions are interesting. I don't want to know if it's a good idea to test in powershell. That's a subjective question that should be asked in a different forum. I want a solution to unit testing powershell. If you think it's a bad idea (it might be), treat it as a fun academic question.

  • 是的,脚本语言将不同的系统粘合在一起.但是,正如已经指出的那样,以动态语言模拟和破坏接缝也很容易.
  • 我不是在问调试"问题.调试是一个非常有用的主题.我让别人问.
  • 也许PS脚本应该很简单.该语言支持模块化,并且不可避免地会在PS中实现复杂的流程(即使是一个不好的主意).
  • 此问题的答案不是您不能".我可以看到(从链接的博客-有点旧了),有些人在解决这个问题上取得了进展.

要重述:如何以xUnit风格实现Powershell逻辑的自动化测试?集成测试很有趣,而打破依赖关系的单元测试则最有趣.

To re-state: How do you implement an automated testing of Powershell logic in the style of xUnit? Integration tests are interesting, unit tests that break dependencies most interesting.

推荐答案

Scott Muc启动了一个用于PowerShell的轻量级BDD框架项目Pester:

Scott Muc has started a project for a lightweight BDD framework for PowerShell called Pester:

https://github.com/pester/Pester

这篇关于如何在Powershell中进行TDD和单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆