Nunit 테스트를 처음 사용했습니다. 데이터베이스에 데이터를 삽입하는 메서드의 테스트 메서드를 작성하려고합니다.Nunit - 데이터 삽입 테스트 문제
내 코드와 같은 것입니다 : 내가 테스트를 실행할 때이 오류가
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MBT.Datastore;
using System.Data;
using MBT.Entities;
public class TagStore
{
private string _connectionString = string.Empty;
public TagStore()
{
this._connectionString = SqlHelper.GetConnectionString();
}
public bool InsertTag(Tag tag)
{
bool isInserted = false;
using (DatabaseHelper helper = Utility.DbHelper)
{
int tagsAdded = helper
.AddInputParameter("@Tag", tag.TagName)
.AddInputParameter("@ParentTagId", tag.ParentTagId)
.ExecuteNonQuery("Proc_InsertTags", CommandType.StoredProcedure);
if (tagsAdded > 0)
{
isInserted = true;
}
}
return isInserted;
}
}
처럼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NUnit.Framework;
using MBT.Entities;
[TestFixture]
public class TagStoreTest
{
private Tag testTag;
public TagStoreTest()
{
this.testTag = new Tag();
}
[Test]
public void InsertTagTest()
{
TagStore tagSt = new TagStore();
bool isInserted = tagSt.InsertTag(this.testTag);
Assert.IsTrue(isInserted);
}
[SetUp]
public void Setup()
{
this.testTag.TagName = "testtagthroughNunit";
}
[TearDown]
public void TearDown()
{
}
}
그리고 실제 TagStore 코드입니다 : TagStoreTest.InsertTagTest: System.NullReferenceException : Object reference not set to an instance of an object.
그리고 코드 라인 TagStore tagSt = new TagStore();
이 빨간색으로 강조 표시됩니다 .
내 프로젝트가 성공적으로 빌드되기 때문에 나에게 무슨 일이 생길지 모르지만 테스트를 실행할 때 오류가 발생합니다.
NUNIT를 실행할 때 일반적으로 스택 추적이 있습니다. 또한 SqlHelper.GetConnectionString()에는 유닛 테스트 중에 올바르게 인스턴스화하지 않는 외부 종속성이 있습니까? – Alex