我用NUnit Testcase编写了一个测试。我已经定义了文件名'irm_xxx_tbbmf_xu.csv.ovr'以及我希望该文件输出的数据。
我已经定义了一个变量processFilePath
,它包含该文件的位置以及NUnit TestCase
属性参数中的文件名。
我的问题是我写processFilePath
的方式如何编写它,以便它像我期望的那样从[NUnit.Framework.TestCase]
中找到文件名。目前它并没有将两者结合起来。 Assert.AreEqual
会按照我写的方式工作吗?
[NUnit.Framework.TestCase("irm_xxx_tbbmf_xu.csv.ovr", "6677,6677_6677,3001,6")]
[NUnit.Framework.TestCase("irm_xxx_tbbmf_xxx.csv.ovr", "6677,22,344")]
public void ValidateInventoryMeasurement(string path, string expected)
{
var processFilePath = "/orabin/product//inputs//actuals/";
var actual = Common.LinuxCommandExecutor.
RunLinuxcommand("cat " + path);
Assert.AreEqual(expected, actual);
}
根据我的评论,在测试中找到要比较的文件时,实际上并没有使用该路径。有多种方法可以组合文件路径 - @ juharr建议使用Path.Combine
是最佳实践(特别是在Windows上),但你真的可以使用任何技术进行字符串连接 - 我已经使用字符串插值来执行此操作。
using System; // Other usings
using NUnit.Framework;
namespace MyTests
{
....
[TestCase("irm_xxx_tbbmf_xu.csv.ovr", "6677,6677_6677,3001,6")]
[TestCase("irm_xxx_tbbmf_xxx.csv.ovr", "6677,22,344")]
public void ValidateInventoryMeasurement(string path, string expected)
{
const string processFilePath = "/orabin/product/inputs/actuals/";
var actual = Common.LinuxCommandExecutor
.RunLinuxcommand($"cat {processFilePath}{path}");
Assert.AreEqual(expected, actual);
}
笔记
Common.LinuxCommandExecutor
processFilePath
路径是恒定的,可以变成const string
NUnit.Framework
,然后您将不需要重复完整的命名空间NUnit.Framework.TestCase
,即只需[TestCase(..)]
cat
的输出上观察无关的空白。在这种情况下,您可以考虑: Assert.AreEqual(expected, actual.Trim());