读取文件时,路径的设置下面3种都可以:
View Code protected void ReadUserName()
{
//string path = "c:\\temp/passport.txt";
//string path = "c:/temp/passport.txt";
string path = "c:\\temp\\passport.txt";
int maxNum = 0;
using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding("gb2312")))
{
string uname;
while ((uname = sr.ReadLine()) != null)
{
maxNum++;
uname = uname.Split(',')[1];
}
}
Assert.AreEqual(2, maxNum);
}
使用TestDriven.NET 3 单元测试
1 在安装目录TestDriven.NET 找到Nunit.Framwork.dll,在项目引用中添加
2 测试类文件头添加using NUnit.Framework;
3
4 每一种都有可以测试通过
![ContractedBlock.gif](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
{
//string path = "c:\\temp/passport.txt";
//string path = "c:/temp/passport.txt";
string path = "c:\\temp\\passport.txt";
int maxNum = 0;
using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding("gb2312")))
{
string uname;
while ((uname = sr.ReadLine()) != null)
{
maxNum++;
uname = uname.Split(',')[1];
}
}
Assert.AreEqual(2, maxNum);
}
使用TestDriven.NET 3 单元测试
1 在安装目录TestDriven.NET 找到Nunit.Framwork.dll,在项目引用中添加
2 测试类文件头添加using NUnit.Framework;
3
![](https://img-blog.csdnimg.cn/2022010707073994818.png)
4 每一种都有可以测试通过
![](https://img-blog.csdnimg.cn/2022010707073922052.png)
转载于:https://blog.51cto.com/gnhao/1111328