コード例 #1
0
 public static extern bool CreateProcess(string lpApplicationName,
        string lpCommandLine, IntPtr lpProcessAttributes,
        IntPtr lpThreadAttributes,
        bool bInheritHandles, ProcessCreationFlags dwCreationFlags,
        IntPtr lpEnvironment, string lpCurrentDirectory,
        ref StartupInfo lpStartupInfo,
        out ProcessInfo lpProcessInformation);
コード例 #2
0
        public override bool run(TestFixturOption testFixturOption, DTE2 applicationObject)
        {
            try
            {
                string output = string.Empty;
                string tvTestFixtureOptions = string.Empty;
                string tvOutputFileFullname = string.Empty;

                if (testFixturOption.CClass != null)
                {
                    tvTestFixtureOptions = " /fixture:";

                    tvTestFixtureOptions += testFixturOption.CClass.FullName;

                    tvOutputFileFullname = UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(testFixturOption.CClass.ProjectItem.ContainingProject);

                    tvTestFixtureOptions += " \"" + tvOutputFileFullname + "\"";

                    if (testFixturOption.ConfigurationFile != string.Empty)
                    {
                        tvTestFixtureOptions += " /config:\"" + tvOutputFileFullname + ".config\"";
                    }
                }
                else if (testFixturOption.CFunction != null)
                {
                    tvTestFixtureOptions = " /run:";

                    CodeClass parentClass = testFixturOption.CFunction.Parent as CodeClass;

                    tvTestFixtureOptions += testFixturOption.CFunction.FullName;

                    tvOutputFileFullname = UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(parentClass.ProjectItem.ContainingProject);

                    tvTestFixtureOptions += " \"" + tvOutputFileFullname + "\"";

                    if (tvTestFixtureOptions.Length > 0)
                    {
                        if (testFixturOption.ConfigurationFile != string.Empty)
                        {
                            tvTestFixtureOptions += " /config:\"" + tvOutputFileFullname + ".config\"";
                        }
                    }
                }
                else
                {
                    if (tvOutputFileFullname.Equals(string.Empty))
                    {
                        tvOutputFileFullname = UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(testFixturOption.Project);
                        tvTestFixtureOptions = "\"" + tvOutputFileFullname + "\"";
                    }

                    if (testFixturOption.ConfigurationFile != string.Empty)
                    {
                        tvTestFixtureOptions += " /config:\"" + tvOutputFileFullname + ".config\"";
                    }
                }

                tvTestFixtureOptions += " /xmlConsole";

                ProjectExaminar.GetProjectOutputType(testFixturOption.Project);

                ProjectItem projectItem = ProjectExaminar.GetProjectConfigurationFile(testFixturOption.Project);

                Project project = testFixturOption.Project;

                if (this.binariesDirectory == null || this.binariesDirectory == string.Empty)
                {
                    BrowseForUnitLibraries tvLocateNUnitBinaries = new BrowseForUnitLibraries(
                        UTGHelper.CommonErrors.ERR_UNABLE_TO_LOCATE_NUNIT_INSTALL_FOLDER, BrowseForUnitLibraries.BrowseForNunitDialogType.libraries, this);

                    tvLocateNUnitBinaries.Show();

                    return(false);
                }

                if (this.consoleDirectory == null || this.consoleDirectory == string.Empty)
                {
                    BrowseForUnitLibraries tvLocateNUnitBinaries = new BrowseForUnitLibraries(
                        UTGHelper.CommonErrors.ERR_UNABLE_TO_LOCATE_NUNIT_CONSOLE, BrowseForUnitLibraries.BrowseForNunitDialogType.console, this);

                    tvLocateNUnitBinaries.Show();

                    return(false);
                }

                string processFullPath = System.IO.Path.Combine(this.consoleDirectory, this.ConsoleName);

                if (TestStarted != null)
                {
                    TestStarted();
                }

#if _PROCESS_START_WIN32_
                ProcessTypes.StartupInfo startInfo   = new ProcessTypes.StartupInfo();
                ProcessTypes.ProcessInfo processInfo = new ProcessTypes.ProcessInfo();

                IntPtr ThreadHandle = IntPtr.Zero;

                string commandLine = (arguments != null ? libraryPath + arguments : libraryPath);

                //string commandLine = @"C:\Users\Sam\documents\visual studio 2010\Projects\MyClassLibrary\MyClassLibrary.nunit\bin\Debug\MyClassLibrary.nunit.dll";

                bool success = CreateProcess(processFullPath, commandLine, IntPtr.Zero, IntPtr.Zero, false,
                                             ProcessTypes.ProcessCreationFlags.CREATE_SUSPENDED,
                                             IntPtr.Zero, null, ref startInfo, out processInfo);

                if (!success)
                {
                    UTGHelper.Logger.LogMessage("Failed to start unit test process");
                    return(false);
                }

                ThreadHandle = processInfo.hThread;
                uint PID = processInfo.dwProcessId;

                ResumeThread(ThreadHandle);

                return(true);
#else
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(processFullPath, tvTestFixtureOptions);

                //we choose to redirect output, but we could also just use the TestResult.xml file
                psi.RedirectStandardOutput = true;

                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

                psi.UseShellExecute = false;

                psi.CreateNoWindow = true; //this is the one that works

                System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);

                if (testFixturOption.IsDebugging)
                {
                    AttachToProcessThread(applicationObject);
                }

                System.IO.StreamReader myOutput = process.StandardOutput;

                process.WaitForExit(60000);

                if (!process.HasExited)
                {
                    UTGHelper.ErrorHandler.ShowMessage(UTGHelper.CommonErrors.ERR_UNABLE_TO_RUN_UNITTEST + " " + "Failed to exit process");

                    return(false);
                }

                output += myOutput.ReadToEnd();
#endif
                //This should be fixed by simple passing the argument that suppresses the copyright text /nologo
                output = PatchFunctionMessageTestOutput(output);

                if (output.Equals(string.Empty))
                {
                    UTGHelper.ErrorHandler.ShowMessage(UTGHelper.CommonErrors.ERR_UNABLE_TO_RUN_UNITTEST);

                    return(false);
                }

                System.Xml.XmlDocument xmlTestResultDoc =
                    NUnitXmlResultProccessor.ToXmlDoc(output);

                System.Xml.XmlNodeList xmlTestResultsNodeList =
                    NUnitXmlResultProccessor.GetTestCases(xmlTestResultDoc);

                List <System.Xml.XmlNode> successfulTestSuites =
                    NUnitXmlResultProccessor.GetSuccessfulTestSuites(xmlTestResultsNodeList);

                List <System.Xml.XmlNode> failedTestSuites =
                    NUnitXmlResultProccessor.GetFailedTestSuites(xmlTestResultsNodeList);

                List <System.Xml.XmlNode> failedExecutionSuites =
                    NUnitXmlResultProccessor.GetFailedExecutionSuites(xmlTestResultsNodeList);

                List <UnitTestError> lstUnitTestPassed =
                    NUnitXmlResultProccessor.GetSuccessfulTestSuitesAsUnitTestErrors(successfulTestSuites);

                List <UnitTestError> lstUnitTestErrors =
                    NUnitXmlResultProccessor.GetFailedTestSuitesAsUnitTestErrors(failedTestSuites);

                List <UnitTestError> lstUnitTestsFialedToExecute =
                    NUnitXmlResultProccessor.GetFailedExecutionsAsUnitTestErrors(failedExecutionSuites);

                if (TestEnded != null)
                {
                    TestEnded(testFixturOption.Project, lstUnitTestPassed, lstUnitTestErrors, lstUnitTestsFialedToExecute);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return(false);
        }
コード例 #3
0
      public override bool run(TestFixturOption testFixturOption, DTE2 applicationObject)
      {
         try
         {
            string output = string.Empty;
            string tvTestFixtureOptions = string.Empty;
            string tvOutputFileFullname = string.Empty;

            if (testFixturOption.CClass != null)
            {
               tvTestFixtureOptions = " /fixture:";

               tvTestFixtureOptions += testFixturOption.CClass.FullName;

               tvOutputFileFullname = UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(testFixturOption.CClass.ProjectItem.ContainingProject);

               tvTestFixtureOptions += " \"" + tvOutputFileFullname + "\"";

               if (testFixturOption.ConfigurationFile != string.Empty)
                  tvTestFixtureOptions += " /config:\"" + tvOutputFileFullname + ".config\"";
            }
            else if (testFixturOption.CFunction != null)
            {
               tvTestFixtureOptions = " /run:";

               CodeClass parentClass = testFixturOption.CFunction.Parent as CodeClass;

               tvTestFixtureOptions += testFixturOption.CFunction.FullName;

               tvOutputFileFullname = UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(parentClass.ProjectItem.ContainingProject);

               tvTestFixtureOptions += " \"" + tvOutputFileFullname + "\"";
             
               if (tvTestFixtureOptions.Length > 0)
               {
                  if (testFixturOption.ConfigurationFile != string.Empty)
                     tvTestFixtureOptions += " /config:\"" + tvOutputFileFullname + ".config\"";
               }
            }
            else
            {
               if (tvOutputFileFullname.Equals(string.Empty))
               {
                  tvOutputFileFullname = UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(testFixturOption.Project);
                  tvTestFixtureOptions = "\"" + tvOutputFileFullname + "\"";
               }

               if (testFixturOption.ConfigurationFile != string.Empty)
                  tvTestFixtureOptions += " /config:\"" + tvOutputFileFullname + ".config\"";
            }

            tvTestFixtureOptions += " /xmlConsole";

            ProjectExaminar.GetProjectOutputType(testFixturOption.Project);

            ProjectItem projectItem = ProjectExaminar.GetProjectConfigurationFile(testFixturOption.Project);

            Project project = testFixturOption.Project;

            if (this.binariesDirectory == null || this.binariesDirectory == string.Empty) {
               BrowseForUnitLibraries tvLocateNUnitBinaries = new BrowseForUnitLibraries(
                         UTGHelper.CommonErrors.ERR_UNABLE_TO_LOCATE_NUNIT_INSTALL_FOLDER, BrowseForUnitLibraries.BrowseForNunitDialogType.libraries, this);

               tvLocateNUnitBinaries.Show();

               return false;
            }

            if (this.consoleDirectory == null || this.consoleDirectory == string.Empty) {

               BrowseForUnitLibraries tvLocateNUnitBinaries = new BrowseForUnitLibraries(
                       UTGHelper.CommonErrors.ERR_UNABLE_TO_LOCATE_NUNIT_CONSOLE, BrowseForUnitLibraries.BrowseForNunitDialogType.console, this);

               tvLocateNUnitBinaries.Show();

               return false;
            }

            string processFullPath = System.IO.Path.Combine(this.consoleDirectory, this.ConsoleName);

            if (TestStarted != null)
            {
               TestStarted();
            }

#if _PROCESS_START_WIN32_
            
            ProcessTypes.StartupInfo startInfo = new ProcessTypes.StartupInfo();
            ProcessTypes.ProcessInfo processInfo = new ProcessTypes.ProcessInfo();

            IntPtr ThreadHandle = IntPtr.Zero;

            string commandLine = (arguments != null ? libraryPath + arguments : libraryPath);

            //string commandLine = @"C:\Users\Sam\documents\visual studio 2010\Projects\MyClassLibrary\MyClassLibrary.nunit\bin\Debug\MyClassLibrary.nunit.dll"; 

            bool success = CreateProcess(processFullPath, commandLine, IntPtr.Zero, IntPtr.Zero, false,
               ProcessTypes.ProcessCreationFlags.CREATE_SUSPENDED, 
               IntPtr.Zero, null, ref startInfo, out processInfo);

            if (!success) {
               UTGHelper.Logger.LogMessage("Failed to start unit test process");
               return false;
            }

            ThreadHandle = processInfo.hThread;
            uint PID = processInfo.dwProcessId;

            ResumeThread(ThreadHandle);

            return true;
           
#else

            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(processFullPath, tvTestFixtureOptions);

            //we choose to redirect output, but we could also just use the TestResult.xml file 
            psi.RedirectStandardOutput = true;

            psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            psi.UseShellExecute = false;

            psi.CreateNoWindow = true; //this is the one that works

            System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);

            if (testFixturOption.IsDebugging)
            {
               AttachToProcessThread(applicationObject);
            }

            System.IO.StreamReader myOutput = process.StandardOutput;

            process.WaitForExit(60000);

            if (!process.HasExited)
            {
               UTGHelper.ErrorHandler.ShowMessage(UTGHelper.CommonErrors.ERR_UNABLE_TO_RUN_UNITTEST + " " + "Failed to exit process");

               return false;
            }

            output += myOutput.ReadToEnd();
#endif
            //This should be fixed by simple passing the argument that suppresses the copyright text /nologo 
            output = PatchFunctionMessageTestOutput(output);

            if (output.Equals(string.Empty))
            {

               UTGHelper.ErrorHandler.ShowMessage(UTGHelper.CommonErrors.ERR_UNABLE_TO_RUN_UNITTEST);

               return false;
            }

            System.Xml.XmlDocument xmlTestResultDoc =
               NUnitXmlResultProccessor.ToXmlDoc(output);

            System.Xml.XmlNodeList xmlTestResultsNodeList =
               NUnitXmlResultProccessor.GetTestCases(xmlTestResultDoc);

            List<System.Xml.XmlNode> successfulTestSuites =
              NUnitXmlResultProccessor.GetSuccessfulTestSuites(xmlTestResultsNodeList);

            List<System.Xml.XmlNode> failedTestSuites =
             NUnitXmlResultProccessor.GetFailedTestSuites(xmlTestResultsNodeList);

            List<System.Xml.XmlNode> failedExecutionSuites =
               NUnitXmlResultProccessor.GetFailedExecutionSuites(xmlTestResultsNodeList);

            List<UnitTestError> lstUnitTestPassed =
               NUnitXmlResultProccessor.GetSuccessfulTestSuitesAsUnitTestErrors(successfulTestSuites);

            List<UnitTestError> lstUnitTestErrors =
               NUnitXmlResultProccessor.GetFailedTestSuitesAsUnitTestErrors(failedTestSuites);

            List<UnitTestError> lstUnitTestsFialedToExecute =
               NUnitXmlResultProccessor.GetFailedExecutionsAsUnitTestErrors(failedExecutionSuites);

            if (TestEnded != null)
            {
               TestEnded(testFixturOption.Project, lstUnitTestPassed, lstUnitTestErrors, lstUnitTestsFialedToExecute);
            }

            return true;
         }
         catch (Exception ex)
         {
            Logger.LogException(ex);
         }

         return false;
      }