首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >破坏Travis-CI构建在dotnet测试失败上

破坏Travis-CI构建在dotnet测试失败上
EN

Stack Overflow用户
提问于 2016-10-30 13:50:09
回答 1查看 301关注 0票数 0

做一些概念的证明,我有一个简单的netcore回购和一些xUnit测试在NetCoreXunit,我必须建立在两个应用程序和特拉维斯。我做了一个失败的测试,而Appveyor的构建失败了,但是我很难让Travis也这么做。它愉快地执行测试,并报告其中一个测试失败了,但通过了构建。

在yaml配置中,我一直在Googled上搜索,并试图在脚本步骤中对输出进行管道和解析,但是我的脚本知识不是很好。

如果有人能帮我让特拉维斯失败,我会很感激的。有一个链接从GitHub回购到我的应用程序和特拉维斯构建,如果你承诺回购它应该自动构建。

--UPDATE--所以我甚至解析了两个测试程序集的输出,并正确地识别了是否有测试失败;但是我需要创建一个变量,以便在抛出退出之前对两个程序集进行测试。为了达到这个目的,我不得不跳过愚蠢的圈圈;其中之一是,我似乎无法在没有Travis抱怨的情况下定义一个变量。它也是硬编码的,我想将它扩展到查找所有测试程序集,而不仅仅是硬编码程序集。

代码语言:javascript
复制
after_success:
  # Run tests
  - dotnet test ./src/NetCoreXunit -xml ./out/NetCoreXunit.xml;
    if grep -q 'result="Fail"' ./out/NetCoreXunit.xml ;  then
      echo 'Failed tests detected.';
    else
      echo 'All tests passed.';
    fi;
  - dotnet test ./src/NetCoreXunitB -xml ./out/NetCoreXunitB.xml;
    if grep -q 'result="Fail"' ./out/NetCoreXunitB.xml ;  then
      echo 'Failed tests detected.';
    else
      echo 'All tests passed.';
    fi;

有什么建议值得赞赏:我如何获得所有测试程序集的列表,以及如何声明和设置一个bool,然后我可以用它退出代码?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-30 23:23:51

花了很长时间试图让.travis.yml正常工作;应该一直沿着Python路线前进;如下所示,从yml开始调用。

代码语言:javascript
复制
import os
import sys
import re
from subprocess import call

root_directory = os.getcwd()
print (root_directory)

regexp = re.compile(r'src[\/\\]NetCoreXunit.?$')
result = False
for child in os.walk(root_directory):
    print (child[0])
    if regexp.search(child[0]) is not None:
        print ("Matched")
        test_path = os.path.join(root_directory, child[0])
        if os.path.isdir(test_path):
            print ("IsDir")
            print (test_path)
            os.chdir(test_path)
            call (["dotnet", "test", "-xml", "output.xml"])
            if 'result="Fail"' in open("output.xml").read():
                print (test_path + ": Failed tests detected")
                result = True
            else:
                print (test_path + ": All tests passed")

os.chdir(root_directory)

if result:
    print ("Failed tests detected")
    sys.exit(1)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40329822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档