简体   繁体   English

如何禁用或忽略 bash 自动化测试系统中的测试?

[英]How to disable or ignore a test in bash automated testing system?

I am having a set of .bat files .我有一组 .bat 文件。 each file contains some tests.每个文件都包含一些测试。 How can i disable one of the test ?如何禁用其中一项测试?

the following is an example下面是一个例子

bashTester.sh

#! /bin/bash

bats -T --gather-test-outputs-in $OUTPUT/createEnvironment.bat
bats -T --gather-test-outputs-in $OUTPUT/protocolTest.bat

I want to ignore a test in the protocolTest.bat .我想忽略 protocolTest.bat 中的测试。 The following are my tests in the protocolTest.bats file.以下是我在protocolTest.bats文件中的测试。

protocolTest.bats

@test "test1-protocol" {

}

@test "test2-protocol" {

}

how can i ignore or disable the test "test2-protocol" ?如何忽略或禁用测试“test2-protocol”?

There are two ways to skip tests with BATS:使用 BATS 跳过测试有两种方法:

  • Marking a test as skipped in the code在代码中将测试标记为已跳过
  • Filtering test when running batsbats时的过滤测试

Which solutions works best for you will depend on the context of your question.哪种解决方案最适合您将取决于您的问题的上下文。

skip in the code skip代码

Quoting the " skip : Easily skip tests" section of the manual:引用手册的“ skip :轻松跳过测试”部分

Tests can be skipped by using the skip command at the point in a test you wish to skip.可以在您希望跳过的测试点使用skip命令跳过测试。
... ...
Optionally, you may include a reason for skipping:或者,您可以包括跳过的原因:
... ...
Or you can skip conditionally或者你可以有条件地跳过

To give you an example of all 3 of these:举一个所有这三个的例子:

@test "test2-protocol" {
    skip # Just skip the test

    skip "Some reason to skip this test" # Skip with a reason

    if [ foo != bar ]; then
        skip "foo isn't bar" # Skip under specific circumstances
    fi
}

This last option, using a condition, would also allow you to skip the test when a certain environmental variable is (or isn't) set, giving you more fine-grained control.最后一个选项使用条件,还允许您在设置(或未设置)某个环境变量时跳过测试,从而为您提供更细粒度的控制。

For instance, if the test code look like this:例如,如果测试代码如下所示:

@test "test2-protocol" {
    if [ "${SKIP_TEST}" = 'test2-protocol' ]; then
        skip "Skipping test2-protocol"
    fi
}

and bats is called like this: bats是这样称呼的:

SKIP_TEST='test2-protocol' bats -T --gather-test-outputs-in $OUTPUT/protocolTest.bat

the test will be skipped.考试将被跳过。 Calling bats without setting SKIP_TEST will run all test, without skipping anything.在不设置SKIP_TEST的情况下调用bats将运行所有测试,而不会跳过任何内容。

--filter on run --filter运行时过滤

Quoting the the "Usage" section of the manual :引用手册的“使用”部分

  -f, --filter <regex>      Only run tests that match the regular expression

As the filter needs a match, we need to negate the test you want to exclude.由于过滤器需要匹配,我们需要否定要排除的测试。

Given the example, something like this should work:举个例子,这样的事情应该可以工作:

bats -T --gather-test-outputs-in $OUTPUT/protocolTest.bat --filter 'test[^2]-protocol'

More information about negating regexes can be found on StackOverflow更多关于否定正则表达式的信息可以 在 StackOverflow上找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM