예제 #1
0
 public static TestDefinition FromUnitTestMethod(UnitTestMethod testMethod)
 {
     return(new TestDefinition
     {
         Title = testMethod.Description,
         TestType = testMethod.Method.DeclaringType.FullName,
         MethodName = testMethod.Method.Name,
         Description = testMethod.Description,
         AssemblyFullName = testMethod.Method.DeclaringType.Assembly.FullName
     });
 }
예제 #2
0
        /// <summary>
        /// Executes the required unit test.
        /// </summary>
        /// <param name="unitTestMethod">The unit test method.</param>
        public static void ExecuteRequiredUnitTest(UnitTestMethod unitTestMethod)
        {
            const string ErrorMessage = "Required unit test failed: ";

            try
            {
                unitTestMethod.Invoke();
            }
            catch (Exception e)
            {
                if (e.Message.StartsWith(ErrorMessage))
                {
                    throw;
                }

                Assert.Fail(ErrorMessage + unitTestMethod.Method.Name);
            }
        }
예제 #3
0
        public static void RunUnitTestGroupInFile(FileInfo file, string testGroupName, Dictionary <UnitTestMethod, Exception> failed, List <UnitTestMethod> succeeded)
        {
            Assembly testAssembly = null;

            try
            {
                testAssembly = Assembly.LoadFile(file.FullName);
            }
            catch (Exception ex)
            {
                OutLineFormat("Failed to load assembly from file {0}: {1}", ConsoleColor.Yellow, file.FullName, ex.Message);
                return;
            }

            OutLineFormat("Loaded assembly {0}", ConsoleColor.Green, testAssembly.FullName);
            List <UnitTestMethod> testMethods = UnitTestMethod.FromAssembly(testAssembly).Where(unitTestMethod =>
            {
                if (unitTestMethod.Method.HasCustomAttributeOfType <TestGroupAttribute>(out TestGroupAttribute testGroupAttribute))
                {
                    return(testGroupAttribute.Groups.Contains(testGroupName));
                }

                return(false);
            }).ToList();

            OutLineFormat("Found ({0}) tests in group ({1}) in assembly ({2})", ConsoleColor.Blue, testMethods.Count, testGroupName, testAssembly.FullName);
            testMethods.Each(testMethod =>
            {
                if (testMethod.TryInvoke(ex =>
                {
                    OutLineFormat("{0} failed: {1}", testMethod.Description, ex.Message);
                    failed.Add(testMethod, ex);
                }))
                {
                    succeeded.Add(testMethod);
                }
                ;
            });
        }
예제 #4
0
        public void TestMethod1()
        {
            Assert.IsTrue(UnitTestMethod.TestLPMedianDataTable());

            Assert.AreEqual(UnitTestMethod.TestTOUMedianDataTable(), 2870);
        }