Swift UITest обрабатывает запуск всех тестов и завершение всех тестовых случаев

Выход

echo $var сильно зависит от значения переменной IFS. По умолчанию он содержит символы пробела, табуляции и новой строки:

[ks@localhost ~]$ echo -n "$IFS" | cat -vte
 ^I$

Это означает, что когда оболочка выполняет разделение поля (или разбиение слов), он использует все эти символы в качестве разделителей слов. Это то, что происходит при ссылке на переменную без двойных кавычек, чтобы ее эхо ($var), и поэтому ожидаемый результат изменяется.

. Один из способов предотвратить разделение слов (помимо использования двойных кавычек) - установить IFS к null. См. http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_05 :

Если значение IFS равно null, ни одно поле

Установка в значение null означает установку пустого значения:

IFS=

Тест:

[ks@localhost ~]$ echo -n "$IFS" | cat -vte
 ^I$
[ks@localhost ~]$ var=$'key\nvalue'
[ks@localhost ~]$ echo $var
key value
[ks@localhost ~]$ IFS=
[ks@localhost ~]$ echo $var
key
value
[ks@localhost ~]$ 

1
задан AtulParmar 16 January 2019 в 14:53
поделиться

1 ответ

Это все описано в документации Apple. Вы хотите использовать setUp и tearDown специально.

https://developer.apple.com/documentation/xctest/xctestcase/understanding_setup_and_teardown_for_test_methods

class SetUpAndTearDownExampleTestCase: XCTestCase {

    override class func setUp() { // 1.
        super.setUp()
        // This is the setUp() class method.
        // It is called before the first test method begins.
        // Set up any overall initial state here.
    }

    override func setUp() { // 2.
        super.setUp()
        // This is the setUp() instance method.
        // It is called before each test method begins.
        // Set up any per-test state here.
    }

    func testMethod1() { // 3.
        // This is the first test method.
        // Your testing code goes here.
        addTeardownBlock { // 4.
            // Called when testMethod1() ends.
        }
    }

    func testMethod2() { // 5.
        // This is the second test method.
        // Your testing code goes here.
        addTeardownBlock { // 6.
            // Called when testMethod2() ends.
        }
        addTeardownBlock { // 7.
            // Called when testMethod2() ends.
        }
    }

    override func tearDown() { // 8.
        // This is the tearDown() instance method.
        // It is called after each test method completes.
        // Perform any per-test cleanup here.
        super.tearDown()
    }

    override class func tearDown() { // 9.
        // This is the tearDown() class method.
        // It is called after all test methods complete.
        // Perform any overall cleanup here.
        super.tearDown()
    }

}
0
ответ дан andromedainiative 16 January 2019 в 14:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: