मैं बहुत की तरह एक विशेषता में एक दिया परीक्षण के बारे में विभिन्न जानकारी (कई बग ट्रैकिंग सिस्टम के लिए आईडी) की दुकान:एनयूनीट परीक्षण चलाने के भीतर रनटाइम पर इकाई परीक्षण विधि विशेषताओं को कैसे प्राप्त करें?
[TestCaseVersion("001","B-8345","X543")]
public void TestSomethingOrOther()
आदेश में एक परीक्षण के दौरान यह जानकारी प्राप्त करने में, मैं नीचे दिए गए कोड लिखा है:
System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)
:
public string GetTestID()
{
StackTrace st = new StackTrace(1);
StackFrame sf;
for (int i = 1; i <= st.FrameCount; i++)
{
sf = st.GetFrame(i);
if (null == sf) continue;
MethodBase method = sf.GetMethod();
if (method.GetCustomAttributes(typeof(TestAttribute), true).Length == 1)
{
if (method.GetCustomAttributes(typeof(TestCaseVersion), true).Length == 1)
{
TestCaseVersion tcv =
sf.GetMethod().GetCustomAttributes(typeof(TestCaseVersion), true).OfType<TestCaseVersion>()
.First();
return tcv.TestID;
}
}
}
समस्या यह है कि जब रिलीज मोड में NUnit के माध्यम से परीक्षण चल रहा है, जो विधि परीक्षण नाम और इन विशेषताओं होनी चाहिए निम्नलिखित की जगह है
:अद्यतन जो कोई रुचि रखता है के लिए, मैं ऊपर (निम्नलिखित तरीके से कोड को लागू करने, ताकि विशेषता मान के किसी भी TestCaseVersion विशेषता का उपयोग करता है मौजूदा कोड के किसी भी परिवर्तन किए बिना, पहुँचा जा सकता है घाव
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method, AllowMultiple = false)]
public class TestCaseVersion : PropertyAttribute
{
public TestCaseVersion(string testCaseCode, string story, string task, string description)
{
base.Properties.Add("TestId", testCaseCode);
base.Properties.Add("Description", description);
base.Properties.Add("StoryId", story);
base.Properties.Add("TaskId", task);
}
}
public string GetTestID()
{
return TestContext.CurrentContext.Test.Properties["TestId"];
}
अच्छा अपडेट !!! अगर मैं कर सकता हूं तो मैं आपको दूसरा अपवॉट दूंगा :-) –