我正在關注一本名爲「單元測試的藝術」的書。我已經達到了需要測試使用NUNit寫入的測試方法的程度。作者指示構建項目,然後找到構建的程序集文件的路徑,並指定NUnit的路徑進行測試。在NUnit中構建和加載文件
我的問題是,我似乎無法得到這個大會文件路徑。它位於哪裏?
另外,當我運行我的代碼,我收到以下錯誤:
Error 2 Program 'c:\Users\Documents\Visual Studio 2012\Projects\Loganalyzer\Loganalyzer\obj\Debug\Loganalyzer.exe' does not contain a static 'Main' method suitable for an entry point c:\users\documents\visual studio 2012\Projects\Loganalyzer\Loganalyzer\CSC Loganalyzer
這裏是我的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loganalyzer
{
public class LogAnalyzer
{
public bool IsValidLogFileName(string fileName)
{
if (!fileName.EndsWith(".SLF"))
{
return false;
}
return true;
}
}
}
我下面這是在書中,但不能得到確切的例子它可以像你所看到的那樣工作。我會感謝你的幫助人員。
using Loganalyzer;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogAnalyzerTest
{
[TestFixture]
class LogAnalyzerTest
{
[Test]
public void IsValidFileName_validFile_ReturnsTrue()
{
//Arrange (Arranges objects, creating and setting them up as necessary).
LogAnalyzer analyzer = new LogAnalyzer();
//Act
bool result = analyzer.IsValidLogFileName("whatever.SLF");
//Assert (Asserts that something is as expected)
Assert.IsTrue(result, "file name should be valid");
}
}
}
您可以發佈你的測試夾具/類。 –
@ ChrisMissal,我發佈了我的測試課。我很感謝你的幫助,因爲我從昨天開始一直無法取得進展。 – Stranger