Exemple #1
0
        public void LoadAssemblyTestCases(Assembly assembly)
        {
            foreach (Type t in assembly.GetTypes())
            {
                if (t.GetCustomAttributes(typeof(TestSetAttribute), true).Length > 0)
                {
                    bool allTargets = (Filters == null || Filters.Length == 0) ||
                                      Filters.Any(f => f.StartsWith(t.Name));

                    TestSetAttribute testSetAttr = t.GetCustomAttributes(
                        typeof(TestSetAttribute), true)[0] as TestSetAttribute;

#if DEBUG
                    if (testSetAttr != null && testSetAttr.DebugEnabled)
#else
                    if (testSetAttr != null && testSetAttr.ReleaseEnabled)
#endif
                    {
                        object testSetInstance = System.Activator.CreateInstance(t);
                        if (testSetInstance != null)
                        {
                            TestSetInfo testSetInfo = new TestSetInfo()
                            {
                                Instance = testSetInstance,
                                Name     = t.Name,
                            };

                            foreach (MethodInfo method in testSetInstance.GetType().GetMethods(
                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                            {
                                if ((allTargets ||
                                     ((Filters == null || Filters.Length == 0) ||
                                      Filters.Any(f => method.Name.StartsWith(f, StringComparison.CurrentCultureIgnoreCase)))) &&
                                    method.GetCustomAttributes(typeof(TestCaseAttribute), false).Length > 0)
                                {
                                    TestCaseAttribute testCaseAttr = method.GetCustomAttributes(typeof(TestCaseAttribute), false)[0] as TestCaseAttribute;
                                    if (testCaseAttr != null && ((Filters != null && Filters.Any(f => method.Name.Contains(f))) ||
                                                                 testCaseAttr.DebugEnabled))
                                    {
                                        TestCaseInfo testCaseInfo = new TestCaseInfo
                                        {
                                            Name   = method.Name,
                                            Method = method,
                                            Sort   = testCaseAttr.Sort,
                                        };

                                        testSetInfo.TestCases.Add(testCaseInfo);
                                    }
                                }
                            }

                            if (testSetInfo.TestCases.Count > 0)
                            {
                                testSets.Add(testSetInfo);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        internal bool RunTestCase(TestSetInfo testSetInfo, TestCaseInfo testCaseInfo, List <string> failList)
        {
            object testSet = testSetInfo.Instance;

            stop.Reset();

            if (BeforePerformTestCase != null)
            {
                var evtArg = new TestCaseEventArgs(testSetInfo, testCaseInfo);
                BeforePerformTestCase(this, evtArg);
                if (evtArg.Cancel)
                {
                    return(true);
                }
            }

            GC.Collect(0, GCCollectionMode.Forced);
            long mem = GetProcessMemoryUsage();

            stop.Start();

            try
            {
                testCaseInfo.Method.Invoke(testSet, null);
            }
            catch (TargetInvocationException x)
            {
                testCaseInfo.Exception = x.InnerException;
                if (failList != null)
                {
                    failList.Add(testSetInfo.Name + "." + testCaseInfo.Name);
                }
            }
            catch (TestCaseFailureException x)
            {
                testCaseInfo.Exception = x;
                if (failList != null)
                {
                    failList.Add(testSetInfo.Name + "." + testCaseInfo.Name);
                }
            }

            stop.Stop();

            testCaseInfo.Performed           = true;
            testCaseInfo.ElapsedMilliseconds = stop.ElapsedMilliseconds;
            testCaseInfo.MemoryUsage         = GetProcessMemoryUsage() - mem;

            GC.Collect(0, GCCollectionMode.Forced);

            if (AfterPerformTestCase != null)
            {
                AfterPerformTestCase(this, new TestCaseEventArgs(testSetInfo, testCaseInfo));
            }

            return(testCaseInfo.Exception != null);
        }
Exemple #3
0
 public TestCaseEventArgs(TestSetInfo testSetInfo, TestCaseInfo testCaseInfo)
 {
     this.testSetInfo  = testSetInfo;
     this.testCaseInfo = testCaseInfo;
 }