Shell script automated testing framework, shellscript

Source: Internet
Author: User

Shell script automated testing framework, shellscript

Development background of shUnit2

ShUnit2 is developed based on the log4sh SHELL automated testing. It is used in a similar way as JUnit.

Preparation

1. Download shUnit2

Wget-P ~ /Download http://shunit2.googlecode.com/files/shunit2-2.1.6.tgz

2.Extract

tar -xzvf ~/download/shunit2-2.1.6.tgz

3. Execute Test Cases

~/download/shunit2-2.1.6/examples/equality_test.sh
Internal processing of test execution

The internal processing process of shUnit2 is as follows.

  • Shunit2 will list the test functions starting with "test" during execution.
  • When the oneTimeSetUp function is defined, it is executed.
  • The listed test functions are executed as follows:
    • If the setUp function is defined, execute the function.
    • Execute the test function
    • When the tearDown function is defined, it is executed.
  • When the oneTimeTearDown function is defined, it is executed.
. "$SHUNIT2_HOME"/src/shell/shunit2
Generate Test code

Example:

#! /Bin/sh # file: test/my_function_test.sh # Read the test object... /src/my_function.shoneTimeSetUp () {:} oneTimeTearDown () {:} setUp () {:} tearDown () {:}# test case testMyFunction () {assertTrue "['myfunction 2'-eq 4]"}. "$ SHUNIT2_HOME"/src/shunit2
#!/bin/sh# file: src/my_function.shmyFunction() {  echo `expr $1 \* $1`}
 
Reference: http://d.hatena.ne.jp/oknknic/20110823/1314113501

Write a SHELL Script according to the following content

#! /Bin/ksh
While [1]
Do
Echo "Please enter a filename: \ c"
Read filename
If [-z "$ {filename}"]; then
Continue
Elif [-f "'pwd'/$ {filename}"]; then
More $ {filename}
Break
Fi
Done

What are the automated testing frameworks?

The automated testing framework can be selected based on project requirements.
1. modular framework (test script modularity ).
2. test library architecture ).
3. keyword-driven testing Framework (keyword-driven/table-driven testing ).
4. data-driven testing framework ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.