从 Cygwin 命令行运行所有程序集中的所有 NUnit 测试

发布于 2024-09-17 22:40:18 字数 372 浏览 8 评论 0原文

我正在尝试创建一个简短的 bash 脚本,可以在 cygwin 中运行,以使用 nunit-console 执行 .NET 项目中的所有 nunit 测试。目前,我的 nunit 系统版本别名为“nunit”,因此如果我运行“nunit”,它将执行 nunit-console。

我的第一步是尝试递归地找到所有测试程序集。这最有效:

find . -name *.Test*.dll

但它返回 dll 的 /obj 和 /bin 版本。

其次,我需要找到一种方法,将 find 的所有结果传递给 nunit,最好是在一次执行中,到目前为止我不知道该怎么做。

有任何 cygwin / bash 专家可以提供帮助吗?

I'm trying to create a short bash script someone could run in cygwin to execute all nunit tests in a .NET project using nunit-console. Currently i have the system version of nunit aliased to "nunit" so if i run "nunit" it will execute nunit-console.

My first step was to try and find all the test assemblies recursively. This MOSTLY works:

find . -name *.Test*.dll

but it returns both /obj and /bin versions of a dll.

Second i need to figure out a way to pass all of the results from that find to nunit, preferably in one execution which so far I have no clue how to do.

Any cygwin / bash gurus out there that can help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赏烟花じ飞满天 2024-09-24 22:40:18

程序集列表会动态变化吗?如果它不经常更改,那么您可能不需要确定在运行时运行哪些程序集。相反,通过使用 NUnit 项目可以更好地解决您的问题。例如,创建文件tests.nunit,其内容为:

<NUnitProject>
  <Settings activeconfig="Debug"/>
  <Config name="Debug">
    <assembly path="ProjectA\bin\Debug\App.dll"/>
    <assembly path="ProjectB\bin\Debug\Widget.dll"/>
  </Config>
  <Config name="Release">
   <assembly path="ProjectA\bin\Release\App.dll"/>
    <assembly path="ProjectB\bin\Release\Widget.dll"/>
  </Config>
</NUnitProject>

运行nunit-consoletests.nunit 将运行Debug 文件夹中App 和Widget 程序集中的所有测试。如果不相关,您还可以省略 Config 和 activeconfig 内容,只列出无论活动配置如何都将始终进行测试的程序集。

查看有关在多个程序集上运行的 NUnit 文档

Does the list of assemblies change dynamically? If it doesn't change often then you probably don't need to determine what assemblies to run on at runtime. Rather, your problem is better solved through the use of an NUnit project. For example, create the file tests.nunit, with contents:

<NUnitProject>
  <Settings activeconfig="Debug"/>
  <Config name="Debug">
    <assembly path="ProjectA\bin\Debug\App.dll"/>
    <assembly path="ProjectB\bin\Debug\Widget.dll"/>
  </Config>
  <Config name="Release">
   <assembly path="ProjectA\bin\Release\App.dll"/>
    <assembly path="ProjectB\bin\Release\Widget.dll"/>
  </Config>
</NUnitProject>

Running nunit-console tests.nunit would run all the tests in the App and Widget assemblies, in the Debug folder. You can also omit the Config and activeconfig stuff if it's not relevant and just list assemblies that will always be tested regardless of active configuration.

Check out the NUnit documentation on running on multiple assemblies.

这是我的工作脚本

check_err()
{
    # parameter 1 is last exit code
    # parameter 2 is error message that should be shown if error code is not 0
    if [ "${1}" -ne "0" ]; then
        cat '~temp.log'
        echo ${2}
        rm -f '~temp.log' > /dev/null
        exit ${1}
    fi;
    rm -f '~temp.log' > /dev/null
}

for i in `find . -print | grep 'bin/Debug/[^/]*\.Tests\.dll

但是有一个微妙的问题。 NUnit 有时会返回负错误代码,这对于 Windows 来说是可以的,但对于 *nix 来说是非法的。我不知道 Cygwin 如何处理负退出代码,但 MinGW32 只是将它们视为 0,即 "$?"结果是 ==“0”

好消息,负错误代码对于 NUnit 来说有点罕见,并且表明运行 NUnit 本身存在问题(请参阅 这个问题了解详细信息)。我没有找到解决此问题的方法,因此我仅在构建服务器上进行负错误代码检查。在本地 bash 控制台中,我只提供积极的信息。

`; do echo "Running tests from ${i} with NUnit..."; cmd.exe /c "Lib\NUnit\nunit-console.exe ${i} /framework:net-4.0" > '~temp.log' check_err $? "Some tests failed." done

但是有一个微妙的问题。 NUnit 有时会返回负错误代码,这对于 Windows 来说是可以的,但对于 *nix 来说是非法的。我不知道 Cygwin 如何处理负退出代码,但 MinGW32 只是将它们视为 0,即 "$?"结果是 ==“0”

好消息,负错误代码对于 NUnit 来说有点罕见,并且表明运行 NUnit 本身存在问题(请参阅 这个问题了解详细信息)。我没有找到解决此问题的方法,因此我仅在构建服务器上进行负错误代码检查。在本地 bash 控制台中,我只提供积极的信息。

Here is my working script for this

check_err()
{
    # parameter 1 is last exit code
    # parameter 2 is error message that should be shown if error code is not 0
    if [ "${1}" -ne "0" ]; then
        cat '~temp.log'
        echo ${2}
        rm -f '~temp.log' > /dev/null
        exit ${1}
    fi;
    rm -f '~temp.log' > /dev/null
}

for i in `find . -print | grep 'bin/Debug/[^/]*\.Tests\.dll

But there's a subtle problem. NUnit sometimes returns negative error codes which is OK for windows, but illegal for *nix. I don't know how Cygwin works with negative exit codes but MinGW32 just treats them as 0, i.e. "$?" == "0" as a result.

Good news, negative error codes are somewhat rare for NUnit and are indicating problems with running NUnit itself (see this question for details). I didn't find a workaround for this problem, so I have negative error code check only on build server. Locally from bash console I'm handing only positive ones.

`; do echo "Running tests from ${i} with NUnit..."; cmd.exe /c "Lib\NUnit\nunit-console.exe ${i} /framework:net-4.0" > '~temp.log' check_err $? "Some tests failed." done

But there's a subtle problem. NUnit sometimes returns negative error codes which is OK for windows, but illegal for *nix. I don't know how Cygwin works with negative exit codes but MinGW32 just treats them as 0, i.e. "$?" == "0" as a result.

Good news, negative error codes are somewhat rare for NUnit and are indicating problems with running NUnit itself (see this question for details). I didn't find a workaround for this problem, so I have negative error code check only on build server. Locally from bash console I'm handing only positive ones.

彩扇题诗 2024-09-24 22:40:18

像这样的东西:

find . -name "*.Test*.dll" -path /path/to/skip -prune -o -exec nunit {} \;

未经测试 - 首先尝试这样看看它是否为您提供了正确的文件:

find . -name "*.Test*.dll" -path /path/to/skip -prune -o -print

Something like this:

find . -name "*.Test*.dll" -path /path/to/skip -prune -o -exec nunit {} \;

Untested - try it like this first to see if it gives you the correct files:

find . -name "*.Test*.dll" -path /path/to/skip -prune -o -print
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文