GitLab CI-如何验证Unity3D测试是否实际通过
这是我的gitlab-ci.yml:GitLab CI-如何验证Unity3D测试是否实际通过,unity3d,continuous-integration,gitlab,Unity3d,Continuous Integration,Gitlab,这是我的gitlab-ci.yml: variables: GIT_STRATEGY: fetch GIT_CLONE_PATH: $CI_BUILDS_DIR GIT_DEPTH: 10 GIT_CLEAN_FLAGS: none stages: - test - build unit-test: script: "C:\\'Program Files'\\Unity\\Hub\\Editor\\'2019.4.3f1'\\Editor\\Unity.e
variables:
GIT_STRATEGY: fetch
GIT_CLONE_PATH: $CI_BUILDS_DIR
GIT_DEPTH: 10
GIT_CLEAN_FLAGS: none
stages:
- test
- build
unit-test:
script: "C:\\'Program Files'\\Unity\\Hub\\Editor\\'2019.4.3f1'\\Editor\\Unity.exe \
-runTests \
-batchmode \
-projectPath . \
-logFile ./log.txt \
-testResults ./unit-tests.xml"
stage: test
tags:
- unity
unity-build:
stage: build
script: echo 'Building...'
tags:
- unity
以下是管道的输出:
Running with gitlab-runner 13.1.1 (6fbc7474)
on Desktop ryBW4ftU
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on DESKTOP-G62KPLQ...
Getting source from Git repository
00:06
Fetching changes with git depth set to 10...
Reinitialized existing Git repository in X:/ScarsOFHonor_CI/.git/
Checking out 8ca0d362 as master...
Encountered 2 file(s) that should have been pointers, but weren't:
ProjectSettings/EditorSettings.asset
ProjectSettings/XRSettings.asset
git-lfs/2.4.2 (GitHub; windows amd64; go 1.8.3; git 6f4b2e98)
Skipping Git submodules setup
Executing "step_script" stage of the job script
01:18
$ C:\'Program Files'\Unity\Hub\Editor\'2019.4.3f1'\Editor\Unity.exe -runTests -batchmode -projectPath . -logFile ./log.txt -testResults ./unit-tests.xml
. is not a valid directory name. Please make sure there are no unallowed characters in the name.
(Filename: C:\buildslave\unity\build\Runtime/Utilities/FileVFS.cpp Line: 218)
. is not a valid directory name. Please make sure there are no unallowed characters in the name.
(Filename: C:\buildslave\unity\build\Runtime/Utilities/FileVFS.cpp Line: 218)
Job succeeded
正如您所看到的,管道顺利通过。然而,这不应该是真的。我故意创建了一个推送失败的测试
请参阅单元测试.xml的内容:
<?xml version="1.0" encoding="utf-8"?>
<test-run id="2" testcasecount="1" result="Failed(Child)" total="1" passed="0" failed="1" inconclusive="0" skipped="0" asserts="0" engine-version="3.5.0.0" clr-version="4.0.30319.42000" start-time="2020-07-17 11:40:32Z" end-time="2020-07-17 11:40:32Z" duration="0.105692">
<test-suite type="TestSuite" id="1007" name="ScarsOFHonor" fullname="ScarsOFHonor" runstate="Runnable" testcasecount="1" result="Failed" site="Child" start-time="2020-07-17 11:40:32Z" end-time="2020-07-17 11:40:32Z" duration="0.105692" total="1" passed="0" failed="1" inconclusive="0" skipped="0" asserts="0">
<properties />
<failure>
<message><![CDATA[One or more child tests had errors]]></message>
</failure>
<test-suite type="Assembly" id="1010" name="EditMode.dll" fullname="X:/ScarsOFHonor_CI/Library/ScriptAssemblies/EditMode.dll" runstate="Runnable" testcasecount="1" result="Failed" site="Child" start-time="2020-07-17 11:40:32Z" end-time="2020-07-17 11:40:32Z" duration="0.079181" total="1" passed="0" failed="1" inconclusive="0" skipped="0" asserts="0">
<properties>
<property name="_PID" value="27144" />
<property name="_APPDOMAIN" value="Unity Child Domain" />
<property name="platform" value="EditMode" />
</properties>
<failure>
<message><![CDATA[One or more child tests had errors]]></message>
</failure>
<test-suite type="TestSuite" id="1011" name="Tests" fullname="Tests" runstate="Runnable" testcasecount="1" result="Failed" site="Child" start-time="2020-07-17 11:40:32Z" end-time="2020-07-17 11:40:32Z" duration="0.076239" total="1" passed="0" failed="1" inconclusive="0" skipped="0" asserts="0">
<properties />
<failure>
<message><![CDATA[One or more child tests had errors]]></message>
</failure>
<test-suite type="TestFixture" id="1008" name="DummyTest" fullname="Tests.DummyTest" classname="Tests.DummyTest" runstate="Runnable" testcasecount="1" result="Failed" site="Child" start-time="2020-07-17 11:40:32Z" end-time="2020-07-17 11:40:32Z" duration="0.067615" total="1" passed="0" failed="1" inconclusive="0" skipped="0" asserts="0">
<properties />
<failure>
<message><![CDATA[One or more child tests had errors]]></message>
</failure>
<test-case id="1009" name="DummyTestSimplePasses" fullname="Tests.DummyTest.DummyTestSimplePasses" methodname="DummyTestSimplePasses" classname="Tests.DummyTest" runstate="Runnable" seed="785721540" result="Failed" start-time="2020-07-17 11:40:32Z" end-time="2020-07-17 11:40:32Z" duration="0.032807" asserts="0">
<properties />
<failure>
<message><![CDATA[ Expected: 1
But was: 2
]]></message>
<stack-trace><![CDATA[at Tests.DummyTest.DummyTestSimplePasses () [0x00001] in X:\ScarsOFHonor_CI\Assets\Tests\EditMode\DummyTest.cs:15
]]></stack-trace>
</failure>
</test-case>
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-run>
正如您所看到的,有一个失败的测试。为什么我的管道会通过?
当我的测试失败时,是否有任何方法可以将我的结果打印到管道本身并将管道标记为失败?Hm有点脏(实际上非常脏:D),但您可以简单地使用like检查结果文件是否包含单词
,例如
find "<failure>" ./unit-tests.xml > nul && exit 1 || exit 0
脚本完成后,是否可以粘贴echo Exit code is%errorlevel%
的内容?@SergioTanaka这是无论如何都会发生的事情,但由于Unity实际成功完成,它退出时0
只有结果文件提示有失败。。。否则管道已经失败了,我猜你能建议我应该如何确切地更改我的gitlab ci.yml
?通过尝试,我得到了sysntax错误。@VenelinVasilev老实说,我不是一个大型yml专家,但我在底部添加了我的猜测^^^这是我尝试时得到的错误类型。另外,“
导致无效的yml,我将其更改为”
,加上&&
之前的第一个命令的结果似乎是即时的。但是,它会在相当长的一段时间后生成xml
文件。@VenelinVasilev我希望使用一个&
,但它不应该等到上一个命令使用完&
?对于前面讨论的同步测试,我希望在Unity完成测试和编写文件之前不会执行find
script: "C:\\'Program Files'\\Unity\\Hub\\Editor\\'2019.4.3f1'\\Editor\\Unity.exe -runTests -batchmode -projectPath . -logFile ./log.txt -testResults ./unit-tests.xml && find '<failure>' ./unit-tests.xml > nul && exit 1 || exit 0"