我想通过属性来装饰一个测试方法。该属性应该知道关于属性方法的哪些测试被认为是先前的。这是一个例子:
private void DestinationChoiceViewLoaded_AllTpmFeaturesAreEnabled_UIElementsAreSetUpProperly() {
var vut = new DestinationChoiceViewUIWrapper();
UIControlAssert.Clickable(vut.GetNextPageButton());
UIControlAssert.Clickable(vut.GetPreviousPageButton());
}
[PreviousTestInOrder()]
public void Run_DestinationChoiceView_Tests() {
var vut = new DestinationChoiceViewUIWrapper();
UIControlAssert.Clickable(vut.GetNextPageButton());
UIControlAssert.Clickable(vut.GetPreviousPageButton());
}
不知何故,我想将 DestinationChoiceViewLoaded_AllTpmFeaturesAreEnabled_UIElementsAreSetUpProperly 传递给属性构造函数。
我试过了:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class PreviousTestInOrderAttribute : Attribute
{
public string MethodName { get; private set; }
public PreviousTestInOrderAttribute(Expression<Action> memberExpression) {
MethodName = GetMemberName(memberExpression);
}
public static string GetMemberName(Expression<Action> memberExpression) {
MemberExpression expressionBody = (MemberExpression) memberExpression.Body;
return expressionBody.Member.Name;
}
}
但如果我这样做
[PreviousTestInOrder(() => DestinationChoiceViewLoaded_AllTpmFeaturesAreEnabled_UIElementsAreSetUpProperly)]
它不会编译:(