NUnit的3,VS2015
我想用通过TestCase
属性测试异常类型我的方法,但NUnit3TestAdapter
没有看到我在VS2015的测试(我的课是public
):如何通过一次测试来测试我的方法异常集?
[TestCase(null, typeof(ArgumentNullException))]
[TestCase("", typeof(ArgumentException))]
[TestCase(" ", typeof(ArgumentException))]
[TestCase(" \t \t ", typeof(ArgumentException))]
[TestCase("< !!!>", typeof(FileNotFoundException))]
public void InvalidFilePath_ThrowsException<T>(string name,
T exception_type) where T : Exception {
Dictionary<string, string> dict = new Dictionary<string, string>();
Assert.Throws<T>(() => ModelFactory.Current.CreateDocument(name,
dict));
}
更:在这种情况下NUnit3TestAdapter
没有看到我所有的测试......但如果我评论这个测试,然后NUnit3TestAdapter
看到其他检查:
// [TestCase(null, typeof(ArgumentNullException))]
// [TestCase("", typeof(ArgumentException))]
// [TestCase(" ", typeof(ArgumentException))]
// [TestCase(" \t \t ", typeof(ArgumentException))]
// [TestCase("<!!!>", typeof(FileNotFoundException))]
// public void InvalidFilePath_ThrowsException<T>(string name,
// T exception_type) where T : Exception {
// Dictionary<string, string> dict = new Dictionary<string, string>();
// Assert.Throws<T>(() => ModelFactory.Current.CreateDocument(name,
// dict));
//}
[Test]
public void InvalidFilePath_ThrowsException_01() {
Dictionary<string, string> dict = new Dictionary<string, string>();
Assert.Throws<ArgumentNullException>(() => ModelFactory.Current
.CreateDocument(null, dict));
}
[Test]
public void InvalidFilePath_ThrowsException_02() {
Dictionary<string, string> dict = new Dictionary<string, string>();
Assert.Throws<ArgumentException>(() => ModelFactory.Current
.CreateDocument("", dict));
}
[Test]
public void InvalidFilePath_ThrowsException_03() {
Dictionary<string, string> dict = new Dictionary<string, string>();
Assert.Throws<ArgumentException>(() => ModelFactory.Current
.CreateDocument(" ", dict));
}
[Test]
public void InvalidFilePath_ThrowsException_04() {
Dictionary<string, string> dict = new Dictionary<string, string>();
Assert.Throws<ArgumentException>(() => ModelFactory.Current
.CreateDocument(" \t \t ", dict));
}
[Test]
public void InvalidFilePath_ThrowsException_05() {
Dictionary<string, string> dict = new Dictionary<string, string>();
Assert.Throws<FileNotFoundException>(() => ModelFactory.Current
.CreateDocument("<!!!>", dict));
}
我怎样才能解决呢?我不想创建五个单独的测试...
看这个问题:http://stackoverflow.com/questions/801153/parametric-test-with-generic-methods – vyrp
如何该信息可以帮助我在我的情况? –
发布了一个答案 – vyrp