我有一个测试课和一个像下面这样的课。
public class Foo
{
private IDbOjbect _db;
public Foo(string conn)
{
_db = new DbOjbect(conn);
}
internal Foo(IDbObject db)
{
_db= db;
}
internal bool TestOne()
{
if (_db.CurrentDbType == DBType.Oracle)
{
//do something
return true;
}
return false;
}
internal bool TestTwo()
{
if (_db.CurrentDbType == DBType.SqlServer ||
_db.CurrentDbType == DBType.SqlServerCE)
{
//do something
return true
}
return false;
}
internal bool TestThree()
{
if (_db.CurrentDbType == DBType.MySql ||
_db.CurrentDbType == DBType.PostgreSQL ||
_db.CurrentDbType == DBType.SQLite)
{
//do something
return true
}
return false;
}
public void RunProcesses()
{
TestOne();
TestTwo();
TestThree();
}
}
[TestFixture("sqlserver")]
[TestFixture("sqlserverce")]
[TestFixture("oracle")]
[TestFixture("mysql")]
[TestFixture("sqlite")]
[TestFixture("postgre")]
public class Tests
{
private string _conn;
private Foo f;
public Tests(string conn)
{
_conn = conn;
}
[SetUp]
public void SetUp()
{
db = new Mock<IDbObject>();
switch (_conn)
{
case "sqlserver":
db.Setup(x => x.CurrentDbType).Returns(DBType.SqlServer);
break;
case "sqlserverce":
db.Setup(x => x.CurrentDbType).Returns(DBType.SqlServerCE);
break;
case "mysql":
db.Setup(x => x.CurrentDbType).Returns(DBType.MySql);
break;
case "postgre":
db.Setup(x => x.CurrentDbType).Returns(DBType.PostgreSQL);
break;
case "sqlite":
db.Setup(x => x.CurrentDbType).Returns(DBType.SQLite);
break;
case "oracle":
db.Setup(x => x.CurrentDbType).Returns(DBType.Oracle);
break;
}
f = new Foo(db.Object);
}
[Test]
public void TestOne()
{
Assert.IsTrue(f.TestOne());
}
[Test]
public void TestTwo()
{
Assert.IsTrue(f.TestTwo());
}
[Test]
public void TestThree()
{
Assert.IsTrue(f.TestThree());
}
}
当 _conn 是 oracle 时,我想运行 TestOne 方法。当 _conn 是 sqlserver 或 sqlserverce 时,我想运行 TestThree 方法。当 _conn 是 mysql、sqlite 或 postgre 时,我想运行 TestTwo 方法。我怎样才能做到这一点 ?是否有 nunit 的属性?