Running a single KIWI spec with xctool

2019-06-26 05:19发布

Has anyone been able to successfully pass the KW_SPEC variable to xctool. I'm trying to run a single KIWI spec by using https://github.com/kiwi-bdd/Kiwi/wiki/Kiwi-FAQ#q-how-do-i-run-a-single-spec-describecontextit.

I can run all the tests successfully with xctool but it doesn't seem to pick up the KW_SPEC value. I've tried it in a lot of different places with the command line but no luck.

e.g.:

xctool -destination 'platform=iOS Simulator,name=iPad Retina,OS=latest'
    -sdk iphonesimulator -workspace SampleProject.xcworkspace 
    -scheme SampleProject KW_SPEC=NewAssessmentTests.m:12 test 
    -only SampleProject_Acceptance_Tests

Using Kiwi v2.3.1 and xctool 0.2.3

Cheers, Mo

1条回答
Bombasti
2楼-- · 2019-06-26 06:08

Update 11/03/2015

@OhadSchneider's comment made me realise that KW_SPEC worked for me because I had set it in the test configuration for my scheme (Edit scheme->Test->Arguments->Environment variables). Setting the variable from shell doesn't work as that variable applies only to the actual build, and not when executing the unit test target.
But there's a workaround to this, by modifying the test phase of your scheme and adding a KW_SPEC environment variable with the value $KW_SPEC, this will expand when running xcodebuild to the value passed to the xcodebuild command (as in my original answer). After this, xcode will will gracefully use the passed KW_SPEC variable, xctool still has the skipped teste marked as failure issue. KW_SPEC scheme setting

Original answer

If you want KW_SPEC as an environment variable to xctool (or to any *nix tool), then you have to place it before the command, otherwise it will be considered a build setting:

KW_SPEC=NewAssessmentTests.m:12 xctool 
    -destination 'platform=iOS Simulator,name=iPad Retina,OS=latest'
    -sdk iphonesimulator -workspace SampleProject.xcworkspace 
    -scheme SampleProject test 
    -only SampleProject_Acceptance_Tests

This will however lead to another problem: xctool will report as errored the tests that don't run, and will report the test as failed, even if no tests have failed. xcodebuild doesn't have this problem as it either doesn't do unit tests discovery, or ignore tests that didn't run, a thing that xctool fails to do.

查看更多
登录 后发表回答