Browse Source

Fix unit tests not being run when the 'Run all tests' menu item is selected but the Unit Tests window has not been opened.

pull/23/head
Matt Ward 14 years ago
parent
commit
258f6f7529
  1. 32
      src/AddIns/Analysis/UnitTesting/Src/AbstractRunTestCommand.cs
  2. 20
      src/AddIns/Analysis/UnitTesting/Src/EmptyUnitTestsPad.cs
  3. 2
      src/AddIns/Analysis/UnitTesting/Src/IRunTestCommandContext.cs
  4. 5
      src/AddIns/Analysis/UnitTesting/Src/RunTestCommandContext.cs
  5. 106
      src/AddIns/Analysis/UnitTesting/Test/Tree/AbstractRunTestCommandTests.cs
  6. 63
      src/AddIns/Analysis/UnitTesting/Test/Tree/EmptyUnitTestsPadTests.cs
  7. 38
      src/AddIns/Analysis/UnitTesting/Test/Tree/NoTestsRunWhenUnitTestPadNotCreatedTestFixture.cs
  8. 3
      src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj
  9. 95
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockRunTestCommandContext.cs

32
src/AddIns/Analysis/UnitTesting/Src/AbstractRunTestCommand.cs

@ -54,9 +54,9 @@ namespace ICSharpCode.UnitTesting
public override void Run() public override void Run()
{ {
GetUnitTestsPad(context.OpenUnitTestsPad); GetUnitTestsPad();
selectedTests = new SelectedTests(Owner, this.unitTestsPad.GetProjects()); selectedTests = GetSelectedTests();
if (selectedTests.HasProjects) { if (selectedTests.HasProjects) {
runningTestCommand = this; runningTestCommand = this;
BeforeRun(); BeforeRun();
@ -64,15 +64,24 @@ namespace ICSharpCode.UnitTesting
} }
} }
void GetUnitTestsPad(IUnitTestsPad unitTestsPad) SelectedTests GetSelectedTests()
{ {
if (unitTestsPad != null) { return new SelectedTests(Owner, unitTestsPad.GetProjects());
this.unitTestsPad = unitTestsPad; }
} else {
this.unitTestsPad = new EmptyUnitTestsPad(); void GetUnitTestsPad()
{
unitTestsPad = context.OpenUnitTestsPad;
if (unitTestsPad == null) {
unitTestsPad = CreateEmptyUnitTestsPad();
} }
} }
EmptyUnitTestsPad CreateEmptyUnitTestsPad()
{
return new EmptyUnitTestsPad(context.OpenSolution);
}
/// <summary> /// <summary>
/// Sets the initial workbench state before starting /// Sets the initial workbench state before starting
/// a test run. /// a test run.
@ -167,10 +176,17 @@ namespace ICSharpCode.UnitTesting
BuildProject CreateBuildProjectBeforeTestRun(SelectedTests selectedTests) BuildProject CreateBuildProjectBeforeTestRun(SelectedTests selectedTests)
{ {
var projects = selectedTests.Projects.Where(p => context.RegisteredTestFrameworks.IsBuildNeededBeforeTestRunForProject(p)); IEnumerable<IProject> projects = GetProjectsRequiringBuildBeforeTestRun(selectedTests);
return context.BuildProjectFactory.CreateBuildProjectBeforeTestRun(projects); return context.BuildProjectFactory.CreateBuildProjectBeforeTestRun(projects);
} }
IEnumerable<IProject> GetProjectsRequiringBuildBeforeTestRun(SelectedTests selectedTests)
{
return selectedTests
.Projects
.Where(p => context.RegisteredTestFrameworks.IsBuildNeededBeforeTestRunForProject(p));
}
/// <summary> /// <summary>
/// Stops running the tests. /// Stops running the tests.
/// </summary> /// </summary>

20
src/AddIns/Analysis/UnitTesting/Src/EmptyUnitTestsPad.cs

@ -2,12 +2,25 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Linq;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting namespace ICSharpCode.UnitTesting
{ {
public class EmptyUnitTestsPad : IUnitTestsPad public class EmptyUnitTestsPad : IUnitTestsPad
{ {
Solution solution;
public EmptyUnitTestsPad()
: this(null)
{
}
public EmptyUnitTestsPad(Solution solution)
{
this.solution = solution;
}
public void UpdateToolbar() public void UpdateToolbar()
{ {
} }
@ -22,6 +35,9 @@ namespace ICSharpCode.UnitTesting
public IProject[] GetProjects() public IProject[] GetProjects()
{ {
if (solution != null) {
return solution.Projects.ToArray();
}
return new IProject[0]; return new IProject[0];
} }
@ -30,6 +46,8 @@ namespace ICSharpCode.UnitTesting
return null; return null;
} }
public void CollapseAll() { } public void CollapseAll()
{
}
} }
} }

2
src/AddIns/Analysis/UnitTesting/Src/IRunTestCommandContext.cs

@ -4,6 +4,7 @@
using System; using System;
using ICSharpCode.Core.Services; using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting namespace ICSharpCode.UnitTesting
{ {
@ -19,5 +20,6 @@ namespace ICSharpCode.UnitTesting
IUnitTestMessageService MessageService { get; } IUnitTestMessageService MessageService { get; }
IUnitTestSaveAllFilesCommand SaveAllFilesCommand { get; } IUnitTestSaveAllFilesCommand SaveAllFilesCommand { get; }
IStatusBarService StatusBarService { get; } IStatusBarService StatusBarService { get; }
Solution OpenSolution { get; }
} }
} }

5
src/AddIns/Analysis/UnitTesting/Src/RunTestCommandContext.cs

@ -4,6 +4,7 @@
using System; using System;
using ICSharpCode.Core.Services; using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting namespace ICSharpCode.UnitTesting
{ {
@ -59,5 +60,9 @@ namespace ICSharpCode.UnitTesting
public IStatusBarService StatusBarService { public IStatusBarService StatusBarService {
get { return statusBarService; } get { return statusBarService; }
} }
public Solution OpenSolution {
get { return ProjectService.OpenSolution; }
}
} }
} }

106
src/AddIns/Analysis/UnitTesting/Test/Tree/AbstractRunTestCommandTests.cs

@ -0,0 +1,106 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Tree
{
[TestFixture]
public class AbstractRunTestCommandTests
{
DerivedRunTestCommand runTestCommand;
MockRunTestCommandContext runTestCommandContext;
void CreateRunTestCommand()
{
runTestCommandContext = new MockRunTestCommandContext();
runTestCommand = new DerivedRunTestCommand(runTestCommandContext);
}
void UnitTestsPadNotCreated()
{
runTestCommandContext.MockUnitTestsPad = null;
}
void NoSolutionOpen()
{
runTestCommandContext.Solution = null;
}
IProject SolutionWithOneProjectOpen()
{
var solution = new Solution(new MockProjectChangeWatcher());
var project = new MockCSharpProject(solution, "MyProject");
solution.AddFolder(project);
runTestCommandContext.Solution = solution;
return project;
}
IProject GetFirstProjectTestedByTestRunner()
{
return runTestCommand
.TestRunnersCreated
.First()
.SelectedTestsPassedToStartMethod
.Project;
}
void BuildIsNotNeededBeforeTestRunForProject(IProject expectedProject)
{
MockTestFramework testFramework = RegisterTestFrameworkForProject(expectedProject);
testFramework.IsBuildNeededBeforeTestRun = false;
}
MockTestFramework RegisterTestFrameworkForProject(IProject project)
{
var testFramework = new MockTestFramework();
runTestCommandContext
.MockRegisteredTestFrameworks
.AddTestFrameworkForProject(project, testFramework);
return testFramework;
}
[Test]
public void Run_UnitTestsPadNotCreatedAndNoSolutionOpen_NullReferenceExceptionNotThrown()
{
CreateRunTestCommand();
NoSolutionOpen();
Assert.DoesNotThrow(() => runTestCommand.Run());
}
[Test]
public void Run_UnitTestsPadNotCreatedAndNoSolutionOpen_OnBeforeRunIsNotCalled()
{
CreateRunTestCommand();
UnitTestsPadNotCreated();
NoSolutionOpen();
runTestCommand.Run();
Assert.IsFalse(runTestCommand.IsOnBeforeBuildMethodCalled);
}
[Test]
public void Run_UnitTestsPadNotCreatedAndSolutionWithOneProjectOpen_TestsRunForProject()
{
CreateRunTestCommand();
UnitTestsPadNotCreated();
IProject expectedProject = SolutionWithOneProjectOpen();
BuildIsNotNeededBeforeTestRunForProject(expectedProject);
runTestCommand.Run();
IProject project = GetFirstProjectTestedByTestRunner();
Assert.AreEqual(expectedProject, project);
}
}
}

63
src/AddIns/Analysis/UnitTesting/Test/Tree/EmptyUnitTestsPadTests.cs

@ -0,0 +1,63 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Tree
{
[TestFixture]
public class EmptyUnitTestsPadTests
{
EmptyUnitTestsPad pad;
Solution solution;
void CreatePadWithNullSolution()
{
CreatePad(null);
}
void CreatePad(Solution solution)
{
pad = new EmptyUnitTestsPad(solution);
}
void CreatePadWithSolution()
{
solution = new Solution(new MockProjectChangeWatcher());
CreatePad(solution);
}
IProject AddProjectToSolution()
{
var project = new MockCSharpProject(solution, "MyProject");
solution.AddFolder(project);
return project;
}
[Test]
public void GetProjects_NullSolution_ReturnsNoProjects()
{
CreatePadWithNullSolution();
int count = pad.GetProjects().Length;
Assert.AreEqual(0, count);
}
[Test]
public void GetProjects_SolutionHasOneProject_ReturnsOneProject()
{
CreatePadWithSolution();
IProject project = AddProjectToSolution();
var expectedProjects = new IProject[] { project };
IProject[] projects = pad.GetProjects();
CollectionAssert.AreEqual(expectedProjects, projects);
}
}
}

38
src/AddIns/Analysis/UnitTesting/Test/Tree/NoTestsRunWhenUnitTestPadNotCreatedTestFixture.cs

@ -1,38 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Tree
{
[TestFixture]
public class NoTestsRunWhenUnitTestPadNotCreatedTestFixture
{
DerivedRunTestCommand runTestCommand;
MockRunTestCommandContext runTestCommandContext;
[SetUp]
public void Init()
{
runTestCommandContext = new MockRunTestCommandContext();
runTestCommand = new DerivedRunTestCommand(runTestCommandContext);
}
[Test]
public void RunTestCommandRunMethodDoesNotThrowNullReferenceException()
{
Assert.DoesNotThrow(delegate { runTestCommand.Run(); });
}
[Test]
public void OnBeforeRunIsNotCalled()
{
runTestCommand.Run();
Assert.IsFalse(runTestCommand.IsOnBeforeBuildMethodCalled);
}
}
}

3
src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj

@ -93,9 +93,11 @@
<Compile Include="Project\TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs" /> <Compile Include="Project\TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs" />
<Compile Include="Project\TestProjectUsesTestFrameworksTestFixture.cs" /> <Compile Include="Project\TestProjectUsesTestFrameworksTestFixture.cs" />
<Compile Include="Project\TwoBaseClassesWithTestMethodsTestFixture.cs" /> <Compile Include="Project\TwoBaseClassesWithTestMethodsTestFixture.cs" />
<Compile Include="Tree\AbstractRunTestCommandTests.cs" />
<Compile Include="Tree\AddNUnitReferenceToProjectTestFixture.cs" /> <Compile Include="Tree\AddNUnitReferenceToProjectTestFixture.cs" />
<Compile Include="Tree\BuildErrorWhenRunningTestsTestFixture.cs" /> <Compile Include="Tree\BuildErrorWhenRunningTestsTestFixture.cs" />
<Compile Include="Tree\ClassTestFixtureSelectedTestFixture.cs" /> <Compile Include="Tree\ClassTestFixtureSelectedTestFixture.cs" />
<Compile Include="Tree\EmptyUnitTestsPadTests.cs" />
<Compile Include="Tree\GoToSelectedBaseClassMethodTestFixture.cs" /> <Compile Include="Tree\GoToSelectedBaseClassMethodTestFixture.cs" />
<Compile Include="Tree\GoToSelectedClassTestFixture.cs" /> <Compile Include="Tree\GoToSelectedClassTestFixture.cs" />
<Compile Include="Tree\GoToSelectedClassWithNoLocationTestFixture.cs" /> <Compile Include="Tree\GoToSelectedClassWithNoLocationTestFixture.cs" />
@ -106,7 +108,6 @@
<Compile Include="Tree\NonTestProjectNotAddedToTestTreeTestFixture.cs" /> <Compile Include="Tree\NonTestProjectNotAddedToTestTreeTestFixture.cs" />
<Compile Include="Tree\NoOwnerForSelectedTestsTestFixture.cs" /> <Compile Include="Tree\NoOwnerForSelectedTestsTestFixture.cs" />
<Compile Include="Tree\NoTestsRunWhenNoTestsSelectedTestFixture.cs" /> <Compile Include="Tree\NoTestsRunWhenNoTestsSelectedTestFixture.cs" />
<Compile Include="Tree\NoTestsRunWhenUnitTestPadNotCreatedTestFixture.cs" />
<Compile Include="Tree\RemoveSolutionFolderTestFixture.cs" /> <Compile Include="Tree\RemoveSolutionFolderTestFixture.cs" />
<Compile Include="Tree\RunAllTestsInPadTestFixture.cs" /> <Compile Include="Tree\RunAllTestsInPadTestFixture.cs" />
<Compile Include="Tree\RunNUnitTestsForMethodTestFixture.cs" /> <Compile Include="Tree\RunNUnitTestsForMethodTestFixture.cs" />

95
src/AddIns/Analysis/UnitTesting/Test/Utils/MockRunTestCommandContext.cs

@ -5,104 +5,69 @@ using System;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.Services; using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
namespace UnitTesting.Tests.Utils namespace UnitTesting.Tests.Utils
{ {
public class MockRunTestCommandContext : IRunTestCommandContext public class MockRunTestCommandContext : IRunTestCommandContext
{ {
UnitTestingOptions options = new UnitTestingOptions(new Properties()); public UnitTestingOptions UnitTestingOptions = new UnitTestingOptions(new Properties());
MockRegisteredTestFrameworks testFrameworks = new MockRegisteredTestFrameworks(); public MockRegisteredTestFrameworks MockRegisteredTestFrameworks = new MockRegisteredTestFrameworks();
MockTestResultsMonitor testResultsMonitor = new MockTestResultsMonitor(); public MockTestResultsMonitor MockTestResultsMonitor = new MockTestResultsMonitor();
MockTaskService taskService = new MockTaskService(); public MockTaskService MockTaskService = new MockTaskService();
MockUnitTestWorkbench workbench = new MockUnitTestWorkbench(); public MockUnitTestWorkbench MockUnitTestWorkbench = new MockUnitTestWorkbench();
MockBuildProjectFactory buildProjectFactory = new MockBuildProjectFactory(); public MockBuildProjectFactory MockBuildProjectFactory = new MockBuildProjectFactory();
MockBuildOptions buildOptions = new MockBuildOptions(); public MockBuildOptions MockBuildOptions = new MockBuildOptions();
MessageViewCategory unitTestCategory = new MessageViewCategory("Unit Tests"); public MockUnitTestsPad MockUnitTestsPad = new MockUnitTestsPad();
MockUnitTestsPad unitTestsPad = new MockUnitTestsPad(); public MockMessageService MockMessageService = new MockMessageService();
MockMessageService messageService = new MockMessageService(); public MockSaveAllFilesCommand MockSaveAllFilesCommand = new MockSaveAllFilesCommand();
MockSaveAllFilesCommand saveAllFilesCommand = new MockSaveAllFilesCommand(); public MockStatusBarService MockStatusBarService = new MockStatusBarService();
MockStatusBarService statusBarService = new MockStatusBarService(); public MessageViewCategory UnitTestMessageViewCategory = new MessageViewCategory("Unit Tests");
public Solution Solution;
public UnitTestingOptions UnitTestingOptions {
get { return options; }
}
public IRegisteredTestFrameworks RegisteredTestFrameworks { public IRegisteredTestFrameworks RegisteredTestFrameworks {
get { return testFrameworks; } get { return MockRegisteredTestFrameworks; }
}
public MockRegisteredTestFrameworks MockRegisteredTestFrameworks {
get { return testFrameworks; }
} }
public MockTestResultsMonitor MockTestResultsMonitor {
get { return testResultsMonitor; }
}
public IUnitTestTaskService TaskService { public IUnitTestTaskService TaskService {
get { return taskService; } get { return MockTaskService; }
}
public MockTaskService MockTaskService {
get { return taskService; }
} }
public IUnitTestWorkbench Workbench { public IUnitTestWorkbench Workbench {
get { return workbench; } get { return MockUnitTestWorkbench; }
}
public MockUnitTestWorkbench MockUnitTestWorkbench {
get { return workbench; }
} }
public IBuildProjectFactory BuildProjectFactory { public IBuildProjectFactory BuildProjectFactory {
get { return buildProjectFactory; } get { return MockBuildProjectFactory; }
}
public MockBuildProjectFactory MockBuildProjectFactory {
get { return buildProjectFactory; }
} }
public IBuildOptions BuildOptions { public IBuildOptions BuildOptions {
get { return buildOptions; } get { return MockBuildOptions; }
}
public MockBuildOptions MockBuildOptions {
get { return buildOptions; }
} }
public MessageViewCategory UnitTestCategory { public MessageViewCategory UnitTestCategory {
get { return unitTestCategory; } get { return UnitTestMessageViewCategory; }
} }
public IUnitTestsPad OpenUnitTestsPad { public IUnitTestsPad OpenUnitTestsPad {
get { return unitTestsPad; } get { return MockUnitTestsPad; }
}
public MockUnitTestsPad MockUnitTestsPad {
get { return unitTestsPad; }
set { unitTestsPad = value; }
} }
public IUnitTestMessageService MessageService { public IUnitTestMessageService MessageService {
get { return messageService; } get { return MockMessageService; }
} }
public MockMessageService MockMessageService {
get { return messageService; }
}
public IUnitTestSaveAllFilesCommand SaveAllFilesCommand { public IUnitTestSaveAllFilesCommand SaveAllFilesCommand {
get { return saveAllFilesCommand; } get { return MockSaveAllFilesCommand; }
} }
public MockSaveAllFilesCommand MockSaveAllFilesCommand { public IStatusBarService StatusBarService {
get { return saveAllFilesCommand; } get { return MockStatusBarService; }
} }
public IStatusBarService StatusBarService { public Solution OpenSolution {
get { return statusBarService; } get { return Solution; }
} }
} }
} }

Loading…
Cancel
Save