의 멤버로 저장합니다. 코드화 된 UI 테스트를 수행하고 있습니다. 기본적으로 UI에 대한 단위 테스트를 수행하고 인스턴스화하는 TestMethod 내에서 자체에 대해 수행 할 어설 션 목록을 저장하는 TestObject
클래스를 만들었습니다 그것.대리자 메서드를 클래스
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;
}
I (예를 들어 Assert 메서드를 저장하고 싶습니다 : 나는 특정 TestObject
에 대해 실행하려는 Assert.AreEqaul(object expected, object actual)
하고 나중에 전화를하지만 올바른 구문의 무언가를 얻기 위해 사투를 벌인거야 나는 또한 사투를 벌인거야. 그 대리자 메서드 (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").
});
}
내 진짜 문제는 디자인 패턴이 정말 도움이 될 수 있지만 디자인 패턴에 정통하지 않다는 것입니다.
당신은 클래스를 가지고 계십니까 당신 방법을 저장하고 싶습니까? 그것 같이 보이지 않는다 그러나 나는 나가 확실하기 위하여 검사 할 것이라는 점을 생각했다. –
그래, 나는 클래스를 소유하고있다 – bflemi3
좋아, 이것은 내가 당신에게 작은 데모를 줄 것이라고 생각한다. 나는 잠시만 기다려 준다. –