单元测试的bash脚本 [英] Unit Testing bash scripts

查看:135
本文介绍了单元测试的bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们拥有一个具有Java的,除了code运行一些的bash脚本的系统。因为我们正试图测试一切,也可能会中断,而这些的bash脚本可能会中断,我们要测试它们。

We have a system that has some bash scripts running besides Java code. Since we are trying to Test Everything That Could Possibly Break, and those bash scripts may break, we want to test them.

问题是,它是难以测试的bash脚本。

The problem is it is hard to test bash scripts.

有没有一种方法或检验的bash脚本最好的做法?或者我们应该放弃使用bash脚本和寻找替代解决方案,可测试?

Is there a way or a best practice to test bash scripts? Or should we quit using bash scripts and look for alternative solutions that are testable?

推荐答案

我接到了一个讨论组如下回答:

I got the following answer from a discussion group:

这是可能的进口(包括,
  不管)一个过程(函数,
  不管它的命名)来自外部
  文件。这是关键,以书面形式
  测试脚本:你打破了你
  脚本进入独立程序
  然后可以导入这两个
  你的行书和您的测试
  脚本,然后你有你的跑步
  脚本尽可能简单。

it's possible to import (include, whatever) a procedure (function, whatever it's named) from an external file. That's the key to writing a testing script: you break up your script into independent procedures that can then be imported into both your running script and your testing script, and then you have your running script be as simple as possible.

这方法是像依赖注入脚本和听起来很有道理。避免的bash脚本,并使用更容易测试和更少的晦涩的语言为preferable。

This method is like dependency injection for scripts, and sounds reasonable. Avoiding bash scripts and using more testable and less obscure language is preferable.

这篇关于单元测试的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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