1

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

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

find . -name *.Test*.dll

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

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

那里有任何 cygwin / bash 大师可以提供帮助吗?

4

3 回答 3

4

程序集列表是否动态变化?如果它不经常更改,那么您可能不需要确定在运行时要在哪些程序集上运行。相反,通过使用 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-console tests.nunit 将运行 Debug 文件夹中 App 和 Widget 程序集中的所有测试。如果不相关,您也可以省略 Config 和 activeconfig 内容,只列出将始终测试的程序集,而不管活动配置如何。

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

于 2010-09-08T07:06:33.210 回答
1

这是我的工作脚本

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$'`; 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 控制台我只处理正面的。

于 2011-09-22T17:51:32.407 回答
0

像这样的东西:

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

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

find . -name "*.Test*.dll" -path /path/to/skip -prune -o -print
于 2010-09-01T16:04:58.573 回答