diff --git a/src/Common/testcentric.common.tests/CommandLineTests.cs b/src/Common/testcentric.common.tests/CommandLineTests.cs index adff7e68f..1600e46a4 100644 --- a/src/Common/testcentric.common.tests/CommandLineTests.cs +++ b/src/Common/testcentric.common.tests/CommandLineTests.cs @@ -33,6 +33,7 @@ public void InputFiles(params string[] files) [TestCase("ProcessModel", null)] [TestCase("DomainUsage", null)] [TestCase("InternalTraceLevel", null)] + [TestCase("DebugTests", false)] [TestCase("DebugAgent", false)] [TestCase("Unattended", false)] public void DefaultOptionValues(string propertyName, object val) @@ -64,6 +65,7 @@ public void DefaultOptionValues(string propertyName, object val) [TestCase("InternalTraceLevel", "--trace:Debug")] [TestCase("ShowHelp", "--help", true)] [TestCase("ShowHelp", "-h", true)] + [TestCase("DebugTests", "--debug", true)] #if DEBUG [TestCase("DebugAgent", "--debug-agent", true)] #endif @@ -110,7 +112,7 @@ public void InvalidOptionsAreDetected(string option) private static PropertyInfo GetPropertyInfo(string propertyName) { PropertyInfo property = typeof(CommandLineOptions).GetProperty(propertyName); - Assert.That(property, Is.Not.Null, "The property '{0}' is not defined", propertyName); + Assert.That(property, Is.Not.Null, $"The property '{propertyName}' is not defined"); return property; } } diff --git a/src/Common/testcentric.common/Options/CommandLineOptions.cs b/src/Common/testcentric.common/Options/CommandLineOptions.cs index f42d5456d..77fd0c222 100644 --- a/src/Common/testcentric.common/Options/CommandLineOptions.cs +++ b/src/Common/testcentric.common/Options/CommandLineOptions.cs @@ -79,6 +79,9 @@ public CommandLineOptions(params string[] args) InternalTraceLevel = v; }); + this.Add("debug", "Launch debugger when user tests start", + v => DebugTests = v != null); + #if DEBUG this.Add("debug-agent", "Launch debugger in testcentric-agent when it starts.", v => DebugAgent = v != null); @@ -126,6 +129,7 @@ public CommandLineOptions(params string[] args) public int MaxAgents { get; private set; } public string InternalTraceLevel { get; private set; } public string WorkDirectory { get; private set; } + public bool DebugTests { get; private set; } public bool DebugAgent { get; private set; } // Error Processing diff --git a/src/TestCentric/testcentric.gui/Presenters/TestCentricPresenter.cs b/src/TestCentric/testcentric.gui/Presenters/TestCentricPresenter.cs index fb9502baa..1acbcec23 100644 --- a/src/TestCentric/testcentric.gui/Presenters/TestCentricPresenter.cs +++ b/src/TestCentric/testcentric.gui/Presenters/TestCentricPresenter.cs @@ -255,7 +255,7 @@ private void WireUpEvents() // Run loaded test automatically if called for if (_model.IsPackageLoaded && _options.RunAllTests) - RunAllTests(); + _model.RunAllTests(); // Currently, --unattended without --run does nothing except exit. else if (_options.Unattended) _view.Close(); @@ -428,7 +428,7 @@ private void WireUpEvents() _view.StatusBarView.Visible = _view.StatusBarCommand.Checked; }; - _view.RunAllCommand.Execute += () => RunAllTests(); + _view.RunAllCommand.Execute += () => _model.RunAllTests(); _view.RunSelectedCommand.Execute += () => RunSelectedTests(); _view.RunFailedCommand.Execute += () => RunFailedTests(); @@ -628,12 +628,6 @@ public void ReloadTests() #region Run Methods - public void RunAllTests() - { - _model.ClearResults(); - _model.RunAllTests(); - } - public void RunSelectedTests() { RunTests(_view.TreeView.SelectedTests); @@ -651,12 +645,6 @@ public void RunTests(TestNode test) public void RunTests(TestNode[] tests) { - if (_settings.Engine.ReloadOnRun) - { - _model.ClearResults(); - _model.ReloadTests(); - } - if (tests != null && tests.Length > 0) _model.RunTests(new TestSelection(tests)); } diff --git a/src/TestCentric/testcentric.gui/Presenters/TreeViewPresenter.cs b/src/TestCentric/testcentric.gui/Presenters/TreeViewPresenter.cs index 7a7b054b3..6a14ac3a5 100644 --- a/src/TestCentric/testcentric.gui/Presenters/TreeViewPresenter.cs +++ b/src/TestCentric/testcentric.gui/Presenters/TreeViewPresenter.cs @@ -60,17 +60,19 @@ public TreeViewPresenter(ITestTreeView view, ITestModel model) _view.ShowCheckBoxes.Checked = showCheckBoxes; _view.RunCommand.Enabled = false; + _view.DebugCommand.Enabled = false; WireUpEvents(); } private void WireUpEvents() { - _model.Events.TestsLoading += (e) => _view.RunCommand.Enabled = false; + _model.Events.TestsLoading += (e) => _view.RunCommand.Enabled = _view.DebugCommand.Enabled = false; _model.Events.TestLoaded += (e) => { _view.RunCommand.Enabled = true; + _view.DebugCommand.Enabled = true; _view.CheckPropertiesDialog(); LoadTests(GetTopDisplayNode(e.Test)); @@ -102,6 +104,7 @@ private void WireUpEvents() reloadState = VisualState.LoadFrom(_view); _view.RunCommand.Enabled = false; + _view.DebugCommand.Enabled = false; }; _model.Events.TestReloaded += (e) => @@ -118,6 +121,7 @@ private void WireUpEvents() _view.Accept(new TestFilterVisitor(_treeFilter)); _view.RunCommand.Enabled = true; + _view.DebugCommand.Enabled = true; }; _model.Events.TestChanged += (e) => @@ -131,6 +135,7 @@ private void WireUpEvents() _model.Events.TestsUnloading += (e) => { _view.RunCommand.Enabled = false; + _view.DebugCommand.Enabled = false; _view.ClosePropertiesDialog(); @@ -152,17 +157,18 @@ private void WireUpEvents() _treeMap.Clear(); }; - _model.Events.TestUnloaded += (e) => _view.RunCommand.Enabled = false; + _model.Events.TestUnloaded += (e) => _view.RunCommand.Enabled = _view.DebugCommand.Enabled = false; _model.Events.RunStarting += (e) => { foreach (var node in _view.Tree.Nodes) ((TestSuiteTreeNode)node).ClearResults(); _view.RunCommand.Enabled = false; + _view.DebugCommand.Enabled = false; _view.CheckPropertiesDialog(); }; - _model.Events.RunFinished += (e) => _view.RunCommand.Enabled = true; + _model.Events.RunFinished += (e) => _view.RunCommand.Enabled = _view.DebugCommand.Enabled = true; _model.Events.TestFinished += (e) => SetTestResult(e.Result); @@ -213,18 +219,20 @@ private void WireUpEvents() _view.RunCommand.Execute += () => { - if (_settings.Engine.ReloadOnRun) - { - _model.ClearResults(); - _model.ReloadTests(); - } - if (_view.ContextNode != null) _model.RunTests(_view.ContextNode.Test); else _model.RunTests(new TestSelection(_view.SelectedTests)); }; + _view.DebugCommand.Execute += () => + { + if (_view.ContextNode != null) + _model.DebugTests(_view.ContextNode.Test); + else + _model.DebugTests(new TestSelection(_view.SelectedTests)); + }; + _view.Tree.ContextMenuStrip.Opened += (s, e) => InitializeContextMenu(); _view.ShowCheckBoxes.CheckedChanged += () => _view.CheckBoxes = _view.ShowCheckBoxes.Checked; diff --git a/src/TestCentric/testcentric.gui/Views/ITestTreeView.cs b/src/TestCentric/testcentric.gui/Views/ITestTreeView.cs index 37cf6b24f..99bd3dab5 100644 --- a/src/TestCentric/testcentric.gui/Views/ITestTreeView.cs +++ b/src/TestCentric/testcentric.gui/Views/ITestTreeView.cs @@ -20,6 +20,7 @@ public interface ITestTreeView ContextMenuStrip ContextMenuStrip { get; } ICommand RunCommand { get; } + ICommand DebugCommand { get; } IChecked ShowFailedAssumptions { get; } IToolStripMenu ProjectMenu { get; } IToolStripMenu ActiveConfiguration { get; } diff --git a/src/TestCentric/testcentric.gui/Views/TestTreeView.Designer.cs b/src/TestCentric/testcentric.gui/Views/TestTreeView.Designer.cs index 84efe0ccd..c65181704 100644 --- a/src/TestCentric/testcentric.gui/Views/TestTreeView.Designer.cs +++ b/src/TestCentric/testcentric.gui/Views/TestTreeView.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.projectMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.activeConfigurationMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.editProjectMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.showCheckBoxesMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.expandAllMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.collapseAllMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -47,7 +48,7 @@ private void InitializeComponent() this.buttonPanel = new System.Windows.Forms.Panel(); this.checkFailedButton = new System.Windows.Forms.Button(); this.clearAllButton = new System.Windows.Forms.Button(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.debugMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.treePanel.SuspendLayout(); this.treeMenu.SuspendLayout(); this.buttonPanel.SuspendLayout(); @@ -80,6 +81,7 @@ private void InitializeComponent() // this.treeMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.runMenuItem, + this.debugMenuItem, this.propertiesMenuItem, this.failedAssumptionsMenuItem, this.projectMenuItem, @@ -89,7 +91,7 @@ private void InitializeComponent() this.collapseAllMenuItem, this.hideTestsMenuItem}); this.treeMenu.Name = "treeMenu"; - this.treeMenu.Size = new System.Drawing.Size(210, 208); + this.treeMenu.Size = new System.Drawing.Size(210, 230); // // runMenuItem // @@ -130,10 +132,15 @@ private void InitializeComponent() this.editProjectMenuItem.Size = new System.Drawing.Size(180, 22); this.editProjectMenuItem.Text = "Edit..."; // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(206, 6); + // // showCheckBoxesMenuItem // - this.showCheckBoxesMenuItem.Name = "showCheckBoxesMenuItem"; this.showCheckBoxesMenuItem.CheckOnClick = true; + this.showCheckBoxesMenuItem.Name = "showCheckBoxesMenuItem"; this.showCheckBoxesMenuItem.Size = new System.Drawing.Size(209, 22); this.showCheckBoxesMenuItem.Text = "Show CheckBoxes"; // @@ -193,10 +200,12 @@ private void InitializeComponent() this.clearAllButton.TabIndex = 0; this.clearAllButton.Text = "Clear All"; // - // toolStripSeparator1 + // debugToolStripMenuItem // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(206, 6); + this.debugMenuItem.Name = "debugToolStripMenuItem"; + this.debugMenuItem.Size = new System.Drawing.Size(209, 22); + this.debugMenuItem.Text = "&Debug"; + this.debugMenuItem.Click += new System.EventHandler(this.debugToolStripMenuItem_Click); // // TestTreeView // @@ -233,5 +242,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem activeConfigurationMenuItem; private System.Windows.Forms.ToolStripMenuItem editProjectMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem debugMenuItem; } } diff --git a/src/TestCentric/testcentric.gui/Views/TestTreeView.cs b/src/TestCentric/testcentric.gui/Views/TestTreeView.cs index 4591db616..b5c5cd2af 100644 --- a/src/TestCentric/testcentric.gui/Views/TestTreeView.cs +++ b/src/TestCentric/testcentric.gui/Views/TestTreeView.cs @@ -41,6 +41,7 @@ public TestTreeView() InitializeComponent(); RunCommand = new ToolStripMenuElement(runMenuItem); + DebugCommand = new ToolStripMenuElement(debugMenuItem); ShowFailedAssumptions = new ToolStripMenuElement(failedAssumptionsMenuItem); ProjectMenu = new ToolStripMenuElement(projectMenuItem); ActiveConfiguration = new ToolStripMenuElement(activeConfigurationMenuItem); @@ -113,6 +114,7 @@ private void WireUpEvents() public event FileDropEventHandler FileDrop; public ICommand RunCommand { get; private set; } + public ICommand DebugCommand { get; private set; } public IChecked ShowFailedAssumptions { get; private set; } public IToolStripMenu ProjectMenu { get; private set; } public IToolStripMenu ActiveConfiguration { get; private set; } @@ -432,5 +434,10 @@ private void FindCheckedNodes(TreeNodeCollection nodes, bool topLevel) } #endregion + + private void debugToolStripMenuItem_Click(object sender, EventArgs e) + { + + } } } diff --git a/src/TestCentric/testcentric.gui/Views/TestTreeView.resx b/src/TestCentric/testcentric.gui/Views/TestTreeView.resx index e986a12bf..fb4039f3e 100644 --- a/src/TestCentric/testcentric.gui/Views/TestTreeView.resx +++ b/src/TestCentric/testcentric.gui/Views/TestTreeView.resx @@ -128,7 +128,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAA2 - DwAAAk1TRnQBSQFMAgEBBQEAASQBAAEkAQABEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA + DwAAAk1TRnQBSQFMAgEBBQEAASwBAAEsAQABEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABIAMAAQEBAAEYBgABGOEAA9YDtwOYA4ADtQPWqwADnAGdAYQBlQHIAYABsQFRASwBRgErARgBJAFc AT0BUgGeAYYBlgOcpQABhAGDAYQByQGBAbQB2AFVAbAB3AFhAbYBZgExAVYBLQEWASYBdgE5AWMB3AFk AbcBzAGJAbcBhAGDAYSfAAOcAckBfgGyAdgBUgGvAd4BaAG5AeMBegHCAeIBhAHEAb8BdAGnAc8BeQG0 diff --git a/src/TestModel/model/ITestModel.cs b/src/TestModel/model/ITestModel.cs index 6cb54c43a..189edc881 100644 --- a/src/TestModel/model/ITestModel.cs +++ b/src/TestModel/model/ITestModel.cs @@ -99,7 +99,7 @@ public interface ITestModel : IDisposable void RunAllTests(); // Debug all tests - void DebugAllTests(); + //void DebugAllTests(); // Run just the specified ITestItem void RunTests(ITestItem testItem); @@ -119,9 +119,6 @@ public interface ITestModel : IDisposable // Get the TestPackage represented by a test,if available TestPackage GetPackageForTest(string id); - // Clear the results for all tests - void ClearResults(); - // Broadcast event when SelectedTestItem changes void NotifySelectedItemChanged(ITestItem testItem); diff --git a/src/TestModel/model/TestModel.cs b/src/TestModel/model/TestModel.cs index a345a12bb..32d8cf946 100644 --- a/src/TestModel/model/TestModel.cs +++ b/src/TestModel/model/TestModel.cs @@ -89,6 +89,8 @@ public static ITestModel CreateTestModel(ITestEngine testEngine, CommandLineOpti model.PackageOverrides.Add(EnginePackageSettings.MaxAgents, options.MaxAgents); if (options.RunAsX86) model.PackageOverrides.Add(EnginePackageSettings.RunAsX86, true); + if (options.DebugTests) + model.PackageOverrides.Add("DebugTests", true); if (options.DebugAgent) model.PackageOverrides.Add("DebugAgent", true); @@ -312,9 +314,11 @@ public void ReloadPackage(TestPackage package, string config) ReloadTests(); } + #region RunningTests + public void RunAllTests() { - RunTests(CategoryFilter); + InternalRunTests(CategoryFilter, false); } public void RunTests(ITestItem testItem) @@ -327,56 +331,53 @@ public void RunTests(ITestItem testItem) if (!CategoryFilter.IsEmpty()) filter = Filters.MakeAndFilter(filter, CategoryFilter); - RunTests(filter); + InternalRunTests(filter, false); } - private void RunTests(TestFilter filter) - { - SetTestDebuggingFlag(false); - - Runner.RunAsync(_events, filter); - } - - public void DebugAllTests() - { - DebugTests(TestFilter.Empty); - } + //public void DebugAllTests() + //{ + // InternalRunTests(TestFilter.Empty, true); + //} public void DebugTests(ITestItem testItem) { - if (testItem != null) DebugTests(testItem.GetTestFilter()); - } - - private void DebugTests(TestFilter filter) - { - SetTestDebuggingFlag(true); - - Runner.RunAsync(_events, filter); + if (testItem != null) InternalRunTests(testItem.GetTestFilter(), true); } - private void SetTestDebuggingFlag(bool debuggingRequested) + private void InternalRunTests(TestFilter filter, bool debugging) { - // We need to re-create the test runner because settings such - // as debugging have already been passed to the test runner. - // For performance, only do this if we did run in a different mode than last time. - if (_lastRunWasDebugRun != debuggingRequested) + // We need to re-create the test runner if changing from debugging to not + // debugging because settings have already been passed to the test runner. + // For performance reasons, we only want to do this if the last run + // used different setting. + if (_lastRunWasDebugRun != debugging) { foreach (var subPackage in TestPackage.SubPackages) - { - subPackage.Settings["DebugTests"] = debuggingRequested; - } + subPackage.Settings["DebugTests"] = debugging; Runner = TestEngine.GetRunner(TestPackage); Runner.Load(); + if (Settings.Engine.ReloadOnRun) + Results.Clear(); + // It is not strictly necessary to load the tests // because the runner will do that automatically, however, // the initial test count will be incorrect causing UI crashes. - _lastRunWasDebugRun = debuggingRequested; + _lastRunWasDebugRun = debugging; } + else if (Settings.Engine.ReloadOnRun) + { + Results.Clear(); + ReloadTests(); + } + + Runner.RunAsync(_events, filter); } + #endregion + public void StopTestRun(bool force) { Runner.StopRun(force); @@ -409,11 +410,6 @@ public TestPackage GetPackageForTest(string id) : null; } - public void ClearResults() - { - Results.Clear(); - } - public void SelectCategories(IList categories, bool exclude) { SelectedCategories = new List(categories);