我在做编码的UI测试,对UI基本单元测试,我创建了一个TestObject
存储要实例化它TestMethod的范围内对自身进行断言的列表类。
public class TestObject {
public string urlToTest;
public List<Assertion> assertions;
}
public class Assertion {
public List<SearchPropertyExpression> searchPropertyExpressions;
public Action assertMethod;
public string expectedValue; // <-- this works fine if I'll always call a method like AreEqual() where it has an expected value, but what if I want to store a method in assertMethod that has different arguments???
}
public class SearchPropertyExpression {
public string expression;
public string value;
}
我想用来存储断言方法(例如: Assert.AreEqaul(object expected, object actual)
,我想针对特定执行TestObject
和后来打电话,但我努力得到的东西,是语法正确的我。也与如何来传递参数对于委托方法(挣扎assertMethod
)时,它实际上调用。所有的方法,我会打电话的内Microsoft.VisualStudio.TestTools.UnitTesting.Assert
。在下面的例子中,我想打电话给Assert.AreEqaul()
但具有可变参数的任何方法可以被调用。这里就是我这么远...
[TestMethod]
public void uiTestConnectionsEducationHomePage() {
//instantiate test object
TestObject testObject = new TestObject() {
urlToTest = "/example/home.aspx",
assertions = {
new Assertion() {
searchPropertyExpressions = {
new SearchPropertyExpression() {
expression = HtmlDiv.PropertyNames.Id,
value = "header"
}
},
assertMethod = Assert.AreEqual // <-- this is wrong,I'm thinking I need to tell assertMethod what arguments to expect here, lambda??
}
}
};
// get handle to browser and launch
UiBrowserWindow uiBrowserWindow = new UiBrowserWindow();
uiBrowserWindow.launchUrl(testObject.urlToTest);
// assertions
testObject.assertions.ForEach(x => {
HtmlDiv htmlObject = new HtmlDiv();
x.searchPropertyExpressions.ForEach(p => {
htmlObject = uiBrowserWindow.uiHtmlDocument.searchHtmlElementByAttributeValue<HtmlDiv>(p.expression, p.value);
});
x.assertMethod; // <-- for this is example the arguments would be (htmlObject, "header").
});
}
我想我真正的问题是,这里有一个设计模式,可以真正帮助我,但我没有很好地设计模式精通。