Unit Testing bash scripts

后端 未结 16 751
暖寄归人
暖寄归人 2020-11-30 18:51

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

16条回答
  •  广开言路
    2020-11-30 19:18

    Try bashtest. It`s simple way to test your scripts. For example, you have do-some-work.sh which change some config files. For example, add new line PASSWORD = 'XXXXX' to config file /etc/my.cfg.

    You write bash commands line by line and then check output.

    Install:

    pip3 install bashtest
    

    Create tests is a just writing bash commands.

    File test-do-some-work.bashtest:

    # run the script  
    $ ./do-some-work.sh > /dev/null
    
    # testing that the line "PASSWORD = 'XXXXX'" is in the file /etc/my.cfg   
    $ grep -Fxq "PASSWORD = 'XXXXX'" /etc/my.cfg && echo "YES"
    YES
    

    Run tests:

    bashtest *.bashtest
    

    You can find some examples here and here

提交回复
热议问题