NUnit: Tham số hóa cho một test

Cách tham số hóa cho một test như sau:

Cách 1: dùng attribute TestCase

public class TF_Login{

//Test này sẽ chạy 3 lần với 3 tập dữ liệu khác nhau
[TestCase("jasontruong","passwordcha")]
[TestCase("suetruong","passwordcon")]
[TestCase("bentruong","passwordcon")]
 public void Login(string username, string password){
    DoSomethingHere
 }

}

Cách 2: dùng attribute TestCaseSource

public class TF_Login{

//Test này sẽ chạy 3 lần với 3 tập dữ liệu khác nhau
[TestCaseSource("TestData")]
 public void Login(string username, string password){
    DoSomethingHere
 }
 public string[][] TestData(){
        string[][] ret= {
                new string[] { "jasontruong","password"},
                new string[] { "suetruong","password"},
                new string[] { "bentruong","password"}
                };
        return ret;
    }

}

Không có nhận xét nào:

Đăng nhận xét