public void LoadSettings(NUnit.Util.ISettings settings) { this.settings = settings; TabInfoCollection info = new TabInfoCollection(); string tabList = (string)settings.GetSetting( Prefix + "TabList" ); if ( tabList != null ) { string[] tabNames = tabList.Split( new char[] { ',' } ); foreach( string name in tabNames ) { string prefix = Prefix + name; string text = (string)settings.GetSetting(prefix + ".Title"); if ( text == null ) break; TabInfo tab = new TabInfo( name, text ); tab.Content = (TextDisplayContent)settings.GetSetting(prefix + ".Content", TextDisplayContent.Empty ); tab.Enabled = settings.GetSetting( prefix + ".Enabled", true ); info.Add( tab ); } } if ( info.Count > 0 ) tabInfo = info; else LoadDefaults(); }
/// <summary> /// Creates an NUnit assembly-level test. /// </summary> /// <param name="assembly">The assembly.</param> /// <param name="runner">The NUnit test runner.</param> public NUnitAssemblyTest(IAssemblyInfo assembly, NUnit.Core.TestRunner runner) : base(assembly.Name, assembly, runner.Test) { Kind = TestKinds.Assembly; this.runner = runner; }
public void NUnitExecute() { #region Find NUnit installation string nunitPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); nunitPath = Path.Combine(nunitPath, NUnit.DEFAULT_NUNIT_DIRECTORY); RegistryKey buildKey = Registry.ClassesRoot.OpenSubKey(@"NUnitTestProject\shell\open\command"); if (buildKey == null) { Assert.Ignore(@"Can't find NUnit installation"); } nunitPath = buildKey.GetValue(null, nunitPath).ToString(); Regex nunitRegex = new Regex("(.+)nunit-gui\\.exe", RegexOptions.IgnoreCase); Match pathMatch = nunitRegex.Match(nunitPath); nunitPath = pathMatch.Groups[1].Value.Replace("\"", ""); #endregion Find NUnit installation MockBuild buildEngine = new MockBuild(); string testDirectory = TaskUtility.makeTestDirectory(buildEngine); NUnit task = new NUnit(); task.BuildEngine = buildEngine; task.Assemblies = TaskUtility.StringArrayToItemArray( Path.Combine(nunitPath, "nunit.framework.tests.dll")); task.WorkingDirectory = testDirectory; task.OutputXmlFile = Path.Combine(testDirectory, @"nunit.framework.tests-results.xml"); Assert.IsTrue(task.Execute(), "Execute Failed"); }
private void OnMeasureUpDownValueChanged(NValueChangeEventArgs args) { NMeasureUpDown measureUpDown = (NMeasureUpDown)args.TargetNode; double value = (double)args.NewValue; NUnit unit = measureUpDown.SelectedUnit; string unitString = unit.ToString(); if (value != 1) { // Make the unit string plural if (unit == NUnit.Inch) { unitString = "inches"; } else if (unit == NUnit.Foot) { unitString = "feet"; } else { unitString += "s"; } } // Log the event m_EventsLog.LogEvent("New value: " + value.ToString() + " " + unitString); }
public void NUnitExecute() { #region Find NUnit installation string nunitPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); nunitPath = Path.Combine(nunitPath, NUnit.DEFAULT_NUNIT_DIRECTORY); RegistryKey buildKey = Registry.ClassesRoot.OpenSubKey(@"NUnitTestProject\shell\open\command"); if (buildKey == null) Assert.Ignore(@"Can't find NUnit installation"); nunitPath = buildKey.GetValue(null, nunitPath).ToString(); Regex nunitRegex = new Regex("(.+)nunit-gui\\.exe", RegexOptions.IgnoreCase); Match pathMatch = nunitRegex.Match(nunitPath); nunitPath = pathMatch.Groups[1].Value.Replace("\"", ""); #endregion Find NUnit installation MockBuild buildEngine = new MockBuild(); string testDirectory = TaskUtility.makeTestDirectory(buildEngine); NUnit task = new NUnit(); task.BuildEngine = buildEngine; task.Assemblies = TaskUtility.StringArrayToItemArray( Path.Combine(nunitPath, "nunit.framework.tests.dll")); task.WorkingDirectory = testDirectory; task.OutputXmlFile = Path.Combine(testDirectory, @"nunit.framework.tests-results.xml"); Assert.IsTrue(task.Execute(), "Execute Failed"); }
/// <summary> /// Method gets called once at the end of running the tests /// </summary> public override void AfterTest(NUnit.Framework.TestDetails testDetails) { if (Environment.OSVersion.Platform != PlatformID.Unix && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILDAGENT_SUBKEY"))) { // End redirection. Otherwise test might fail when we run them multiple // times in NUnit. RegOverridePredefKey(HKEY_CURRENT_USER, UIntPtr.Zero); } base.AfterTest(testDetails); }
private void BuildExposedTypes() { // TODO: add command like option (/expose) to build exposed types // load only exposed types foreach (var type in AppAssembly.GetReferences(false).SelectMany(asm => asm.GetExposedTypes())) { if (type.IsTestFixture()) { NUnit.AddFixture(type); } TypeBuilder.Build(type); } }
/// <summary> /// Method gets called once at the very start of running the tests /// </summary> public override void BeforeTest(NUnit.Framework.TestDetails testDetails) { base.BeforeTest(testDetails); if (Environment.OSVersion.Platform != PlatformID.Unix && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILDAGENT_SUBKEY"))) { UIntPtr hKey; RegCreateKey(HKEY_CURRENT_USER, TmpRegistryKey, out hKey); RegOverridePredefKey(HKEY_CURRENT_USER, hKey); RegCloseKey(hKey); } }
public void SuiteFinished(NUnit.Core.TestResult result) { if(result.FullName.Equals(myRootName)) { return; } JSONClass jsonClass = new JSONClass(); jsonClass.Add("name", result.Name); jsonClass.Add("uuid", myUUID); jsonClass.Add("type", "SuiteFinished"); ConsuloIntegration.SendToConsulo("unityTestState", jsonClass); }
public void SuiteFinished(NUnit.Core.TestResult result) { if ((result.IsError || result.IsFailure) && (result.FailureSite == FailureSite.SetUp || result.FailureSite == FailureSite.TearDown)) { testLog.SendMessage( TestMessageLevel.Error, string.Format("{0} failed for test fixture {1}", result.FailureSite, result.FullName)); if (result.Message != null) testLog.SendMessage(TestMessageLevel.Error, result.Message); if (result.StackTrace != null) testLog.SendMessage(TestMessageLevel.Error, result.StackTrace); } }
public void SuiteStarted(NUnit.Core.TestName testName) { if(myRootName == null) { myRootName = testName.FullName; return; } JSONClass jsonClass = new JSONClass(); jsonClass.Add("uuid", myUUID); jsonClass.Add("name", testName.Name); jsonClass.Add("type", "SuiteStarted"); ConsuloIntegration.SendToConsulo("unityTestState", jsonClass); }
public override void WriteActualValueTo(NUnit.Framework.Constraints.MessageWriter writer) { int lines = Math.Min(expectedLines.Length, actualLines.Length); for (int i = 0; i < lines; i++) { string expectedLine = expectedLines[i]; string actualExLine = actualLines[i]; if (!(expectedLine.Equals(actualExLine))) { writer.WriteActualValue(actualExLine + ", line " + (i + 1).ToString() + Environment.NewLine + expected); return; } } writer.WriteActualValue("actual text is " + actualLines.Length + " lines"); }
/// <summary> /// The delegate to handle the message box is installed. /// </summary> /// <param name="cmd">Contains a NUnit.Extensions.Forms.MessageBoxTester.Command to /// insert the desired reaction.</param> public void WaitForMessageBox(NUnit.Extensions.Forms.MessageBoxTester.Command cmd) { lastMessageTitle = ""; lastMessageText = ""; ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); System.Console.WriteLine("Title: " + tester.Title); System.Console.WriteLine("Message: " + tester.Text); lastMessageTitle = tester.Title; lastMessageText = tester.Text; tester.SendCommand(cmd); }; }
public void NUnitExecuteWhenToolPathIsDefined(int majorVersion, int minorVersion, int number) { string nUnitDirName = string.Format("NUnit {0}.{1}.{2}", majorVersion, minorVersion, number); string nunitPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), nUnitDirName), "bin"); if (!Directory.Exists(nunitPath)) { Assert.Inconclusive("{0} - not found", nunitPath); } MockBuild buildEngine = new MockBuild(); string testDirectory = TaskUtility.makeTestDirectory(buildEngine); NUnit task = new NUnit(); task.ToolPath = nunitPath; task.BuildEngine = buildEngine; task.Assemblies = TaskUtility.StringArrayToItemArray(Path.Combine(nunitPath, "nunit.framework.tests.dll")); task.WorkingDirectory = testDirectory; Assert.IsTrue(task.Execute(), "Execute Failed"); }
public override void WriteDescriptionTo(NUnit.Framework.Constraints.MessageWriter writer) { if (expected == null || actualEx == null) { writer.WriteExpectedValue(expected); } else { int lines = Math.Min(expectedLines.Length, actualLines.Length); for (int i = 0; i < lines; i++) { string expectedLine = expectedLines[i]; string actualExLine = actualLines[i]; if (!(expectedLine.Equals(actualExLine))) { writer.WriteExpectedValue(expectedLine); return; } } writer.WriteExpectedValue("expected text is " + expectedLines.Length + " lines"); } }
private UnitTestResult[] ParseTestList ( NUnit.Core.Test test, string currentAssemblyPath ) { if (test.IsSuite) { var tests = new List<UnitTestResult> (); foreach (var obj in test.Tests) { if (obj is TestAssembly && File.Exists ((obj as TestAssembly).TestName.FullName)) currentAssemblyPath = (obj as TestAssembly).TestName.FullName; if (obj is NUnit.Core.Test) { var results = ParseTestList (obj as NUnit.Core.Test, currentAssemblyPath); tests.AddRange (results); } } return tests.ToArray (); } else { return new[] { CreateNewTestResult (test as TestMethod, currentAssemblyPath) }; } }
public void RunFinished(NUnit.Core.TestResult result) { }
public TestResult Run(NUnit.Framework.Internal.Test test) { TestExecutionContext current = TestExecutionContext.CurrentContext; current.WorkDirectory = System.Environment.CurrentDirectory; current.Listener = this; current.TestObject = test is TestSuite ? null : Reflect.Construct ((test as TestMethod).Method.ReflectedType, null); WorkItem wi = test.CreateWorkItem (Filter ?? TestFilter.Empty); if (test is TestMethod) (test.Parent as TestSuite).GetOneTimeSetUpCommand ().Execute (current); wi.Execute (current); if (test is TestMethod) (test.Parent as TestSuite).GetOneTimeTearDownCommand ().Execute (current); return wi.Result; }
public void Write( NUnit.Core.TestOutput output ) { Write( output.Text ); }
public override bool Execute() { Guard.ArgumentNotNull(nameof(Assemblies), Assemblies); RemotingUtility.CleanUpRegisteredChannels(); XElement?assembliesElement = null; if (NeedsXml) { assembliesElement = new XElement("assemblies"); } var appDomains = default(AppDomainSupport?); switch (AppDomains?.ToLowerInvariant()) { case null: break; case "ifavailable": appDomains = AppDomainSupport.IfAvailable; break; case "true": case "required": appDomains = AppDomainSupport.Required; break; case "false": case "denied": appDomains = AppDomainSupport.Denied; break; default: Log.LogError("AppDomains value '{0}' is invalid: must be 'ifavailable', 'required', or 'denied'", AppDomains); return(false); } switch (MaxParallelThreads) { case null: case "default": break; case "unlimited": maxThreadCount = -1; break; default: int threadValue; if (!int.TryParse(MaxParallelThreads, out threadValue) || threadValue < 1) { Log.LogError("MaxParallelThreads value '{0}' is invalid: must be 'default', 'unlimited', or a positive number", MaxParallelThreads); return(false); } maxThreadCount = threadValue; break; } var originalWorkingFolder = Directory.GetCurrentDirectory(); var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(Log, InternalDiagnosticMessages); using (AssemblyHelper.SubscribeResolveForAssembly(typeof(xunit), internalDiagnosticsMessageSink)) { var reporter = GetReporter(); if (reporter == null) { return(false); } try { logger = new MSBuildLogger(Log); reporterMessageHandler = reporter.CreateMessageHandler(logger, internalDiagnosticsMessageSink).GetAwaiter().GetResult(); if (!NoLogo) { Log.LogMessage(MessageImportance.High, $"xUnit.net v3 MSBuild Runner v{ThisAssembly.AssemblyInformationalVersion} ({IntPtr.Size * 8}-bit {RuntimeInformation.FrameworkDescription})"); } var project = new XunitProject(); foreach (var assembly in Assemblies) { var assemblyFileName = assembly.GetMetadata("FullPath"); var configFileName = assembly.GetMetadata("ConfigFile"); if (configFileName != null && configFileName.Length == 0) { configFileName = null; } var targetFramework = AssemblyUtility.GetTargetFramework(assemblyFileName); var projectAssembly = new XunitProjectAssembly(project) { AssemblyFilename = assemblyFileName, ConfigFilename = configFileName, TargetFramework = targetFramework }; ConfigReader.Load(projectAssembly.Configuration, assemblyFileName, configFileName); if (shadowCopy.HasValue) { projectAssembly.Configuration.ShadowCopy = shadowCopy; } project.Add(projectAssembly); } if (WorkingFolder != null) { Directory.SetCurrentDirectory(WorkingFolder); } var clockTime = Stopwatch.StartNew(); if (!parallelizeAssemblies.HasValue) { parallelizeAssemblies = project.All(assembly => assembly.Configuration.ParallelizeAssemblyOrDefault); } if (parallelizeAssemblies.GetValueOrDefault()) { var tasks = project.Assemblies.Select(assembly => Task.Run(() => ExecuteAssembly(assembly, appDomains).AsTask())); var results = Task.WhenAll(tasks).GetAwaiter().GetResult(); foreach (var assemblyElement in results.WhereNotNull()) { assembliesElement !.Add(assemblyElement); } } else { foreach (var assembly in project.Assemblies) { var assemblyElement = ExecuteAssembly(assembly, appDomains); if (assemblyElement != null) { assembliesElement !.Add(assemblyElement); } } } clockTime.Stop(); if (assembliesElement != null) { assembliesElement.Add(new XAttribute("timestamp", DateTime.Now.ToString(CultureInfo.InvariantCulture))); } if (completionMessages.Count > 0) { var summaries = new TestExecutionSummaries { ElapsedClockTime = clockTime.Elapsed }; foreach (var completionMessage in completionMessages.OrderBy(kvp => kvp.Key)) { summaries.Add(completionMessage.Key, completionMessage.Value); } reporterMessageHandler.OnMessage(summaries); } } finally { reporter.DisposeAsync().GetAwaiter().GetResult(); } } Directory.SetCurrentDirectory(WorkingFolder ?? originalWorkingFolder); if (NeedsXml && assembliesElement != null) { if (Xml != null) { TransformFactory.Transform("xml", assembliesElement, Xml.GetMetadata("FullPath")); } if (XmlV1 != null) { TransformFactory.Transform("xmlv1", assembliesElement, XmlV1.GetMetadata("FullPath")); } if (Html != null) { TransformFactory.Transform("html", assembliesElement, Html.GetMetadata("FullPath")); } if (NUnit != null) { TransformFactory.Transform("nunit", assembliesElement, NUnit.GetMetadata("FullPath")); } if (JUnit != null) { TransformFactory.Transform("junit", assembliesElement, JUnit.GetMetadata("FullPath")); } } // ExitCode is set to 1 for test failures and -1 for Exceptions. return(ExitCode == 0 || (ExitCode == 1 && IgnoreFailures)); }
private void UpdateTestResults(NUnit.Core.TestSuite suite) { ToUnitTestResult(suite); }
private void ToUnitTestResult(NUnit.Core.TestResult result) { if (result.HasResults) { ToUnitTestResult(result.Results); } else { UpdateTest(result.UnitTestResult()); } }
public override void WriteActualValueTo(NUnit.Framework.Constraints.MessageWriter writer) { writer.WriteActualValue(actualValue); }
private void events_TestUnloaded(object sender, NUnit.Util.TestEventArgs args) { availableCategories.Clear(); availableList.Items.Clear(); selectedList.Items.Clear(); excludeCheckbox.Checked = false; excludeCheckbox.Enabled = false; treeMenu.Visible = false; }
private void events_TestLoaded(object sender, NUnit.Util.TestEventArgs args) { treeMenu.Visible = true; availableCategories = this.loader.GetCategories(); availableList.Items.Clear(); selectedList.Items.Clear(); availableList.SuspendLayout(); foreach (string category in availableCategories) availableList.Items.Add(category); // tree may have restored visual state if( !tests.CategoryFilter.IsEmpty ) { ITestFilter filter = tests.CategoryFilter; if ( filter is NUnit.Core.Filters.NotFilter ) { filter = ((NUnit.Core.Filters.NotFilter)filter).BaseFilter; this.excludeCheckbox.Checked = true; } foreach( string cat in ((NUnit.Core.Filters.CategoryFilter)filter).Categories ) if ( this.availableCategories.Contains( cat ) ) { this.availableList.Items.Remove( cat ); this.selectedList.Items.Add( cat ); this.excludeCheckbox.Enabled = true; } UpdateCategoryFilter(); } availableList.ResumeLayout(); }
public void TestFinished(NUnit.Core.TestResult result) { TestResult ourResult = testConverter.ConvertTestResult(result); ourResult.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, Output)); this.testLog.RecordEnd(ourResult.TestCase, ourResult.Outcome); this.testLog.RecordResult(ourResult); Output = ""; }
public void RunFinished(NUnit.Core.TestResult testResult) { this.testResult = testResult; try { this.SaveLastResult( Path.Combine( Path.GetDirectoryName( this.TestFileName ), "TestResult.xml" ) ); events.FireRunFinished( testResult ); } catch( Exception ex ) { this.lastException = ex; events.FireRunFinished( ex ); } }
private void UpdateTestResults(NUnit.Core.TestResult result) { ToUnitTestResult(result); }
private void events_TestReloaded(object sender, NUnit.Util.TestEventArgs args) { // Get new list of available categories availableCategories = this.loader.GetCategories(); // Remove any selected items that are no longer available int index = selectedList.Items.Count; selectedList.SuspendLayout(); while( --index >= 0 ) { string category = selectedList.Items[index].ToString(); if ( !availableCategories.Contains( category ) ) selectedList.Items.RemoveAt( index ); } selectedList.ResumeLayout(); // Put any unselected available items availableList availableList.Items.Clear(); availableList.SuspendLayout(); foreach( string category in availableCategories ) if( selectedList.FindStringExact( category ) < 0 ) availableList.Items.Add( category ); availableList.ResumeLayout(); // Tell the tree what is selected UpdateCategoryFilter(); }
public void SuiteFinished(NUnit.Core.TestResult result) { }
public bool Install(NUnit.Core.Extensibility.IExtensionHost host) { return false; }
public void TestOutput(NUnit.Core.TestOutput testOutput) { }
public override void WriteDescriptionTo(NUnit.Framework.Constraints.MessageWriter writer) { if (expected == null || field == null) { writer.WriteExpectedValue(expected); } else { writer.WriteExpectedValue(field + " is " + expectedValue); } }
private void ToUnitTestResult(NUnit.Core.Test test) { if (test.IsSuite) ToUnitTestResult(test.Tests); else UpdateTest(test.UnitTestResult()); }