Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5844 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
246 changed files with 13426 additions and 2863 deletions
@ -0,0 +1,115 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.Profiler.AddIn; |
||||||
|
using ICSharpCode.Profiler.Controller.Data; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
|
||||||
|
namespace ICSharpCode.Profiler.AddIn |
||||||
|
{ |
||||||
|
public class ProfilerTestRunner : TestRunnerBase |
||||||
|
{ |
||||||
|
ProfilerRunner runner; |
||||||
|
UnitTestingOptions options = new UnitTestingOptions(); |
||||||
|
TestResultsMonitor testResultsMonitor; |
||||||
|
|
||||||
|
public ProfilerTestRunner() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override void Start(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests); |
||||||
|
Start(startInfo, selectedTests); |
||||||
|
} |
||||||
|
|
||||||
|
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options); |
||||||
|
testResultsMonitor = new TestResultsMonitor(); |
||||||
|
app.Results = testResultsMonitor.FileName; |
||||||
|
return app.GetProcessStartInfo(); |
||||||
|
} |
||||||
|
|
||||||
|
void Start(ProcessStartInfo startInfo, SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
LogCommandLine(startInfo); |
||||||
|
|
||||||
|
string path = selectedTests.Project.GetSessionFileName(); |
||||||
|
|
||||||
|
LoggingService.Info("starting profiler..."); |
||||||
|
|
||||||
|
runner = new ProfilerRunner(startInfo, true, new UnitTestWriter(new ProfilingDataSQLiteWriter(path), GetUnitTestNames(selectedTests).ToArray())); |
||||||
|
|
||||||
|
runner.RunFinished += delegate { |
||||||
|
WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(path)); |
||||||
|
AfterFinish(selectedTests, path); |
||||||
|
}; |
||||||
|
|
||||||
|
testResultsMonitor.TestFinished += OnTestFinished; |
||||||
|
testResultsMonitor.Start(); |
||||||
|
runner.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<string> GetUnitTestNames(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
IProjectContent content = ParserService.GetProjectContent(selectedTests.Project); |
||||||
|
|
||||||
|
if (selectedTests.Class == null) { |
||||||
|
var testClasses = content.Classes |
||||||
|
.Where(c => c.Attributes.Any(a => a.AttributeType.FullyQualifiedName == "NUnit.Framework.TestFixtureAttribute")); |
||||||
|
return testClasses |
||||||
|
.SelectMany(c2 => c2.Methods) |
||||||
|
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute")) |
||||||
|
.Select(m2 => m2.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
if (selectedTests.Method == null) { |
||||||
|
return content.Classes |
||||||
|
.Where(c => c.FullyQualifiedName == selectedTests.Class.DotNetName).First().Methods |
||||||
|
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute")) |
||||||
|
.Select(m2 => m2.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
return new[] { selectedTests.Class.DotNetName + "." + selectedTests.Method.Name }; |
||||||
|
} |
||||||
|
|
||||||
|
void AfterFinish(SelectedTests selectedTests, string path) |
||||||
|
{ |
||||||
|
selectedTests.Project.AddSessionToProject(path); |
||||||
|
OnAllTestsFinished(this, new EventArgs()); |
||||||
|
LoggingService.Info("shutting profiler down..."); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Stop() |
||||||
|
{ |
||||||
|
if (this.runner != null && this.runner.Profiler.IsRunning) { |
||||||
|
LoggingService.Info("stopping profiler..."); |
||||||
|
runner.Stop(); |
||||||
|
} |
||||||
|
|
||||||
|
if (testResultsMonitor != null) { |
||||||
|
testResultsMonitor.Stop(); |
||||||
|
testResultsMonitor.Read(); |
||||||
|
testResultsMonitor = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override void Dispose() |
||||||
|
{ |
||||||
|
Stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,332 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
|
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public abstract class AbstractRunTestCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
static AbstractRunTestCommand runningTestCommand; |
||||||
|
IUnitTestsPad unitTestsPad; |
||||||
|
SelectedTests selectedTests; |
||||||
|
IRunTestCommandContext context; |
||||||
|
ITestRunner testRunner; |
||||||
|
|
||||||
|
public AbstractRunTestCommand() |
||||||
|
: this(new RunTestCommandContext()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractRunTestCommand(IRunTestCommandContext context) |
||||||
|
{ |
||||||
|
this.context = context; |
||||||
|
} |
||||||
|
|
||||||
|
protected IRunTestCommandContext Context { |
||||||
|
get { return context; } |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the running test command.
|
||||||
|
/// </summary>
|
||||||
|
public static AbstractRunTestCommand RunningTestCommand { |
||||||
|
get { return runningTestCommand; } |
||||||
|
set { runningTestCommand = value; } |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether a test is currently running.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsRunningTest { |
||||||
|
get { return runningTestCommand != null; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
GetUnitTestsPad(context.OpenUnitTestsPad); |
||||||
|
|
||||||
|
selectedTests = new SelectedTests(Owner, this.unitTestsPad.GetProjects()); |
||||||
|
if (selectedTests.HasProjects) { |
||||||
|
runningTestCommand = this; |
||||||
|
BeforeRun(); |
||||||
|
RunTests(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void GetUnitTestsPad(IUnitTestsPad unitTestsPad) |
||||||
|
{ |
||||||
|
if (unitTestsPad != null) { |
||||||
|
this.unitTestsPad = unitTestsPad; |
||||||
|
} else { |
||||||
|
this.unitTestsPad = new EmptyUnitTestsPad(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the initial workbench state before starting
|
||||||
|
/// a test run.
|
||||||
|
/// </summary>
|
||||||
|
void BeforeRun() |
||||||
|
{ |
||||||
|
ClearTasks(); |
||||||
|
ClearUnitTestCategoryText(); |
||||||
|
|
||||||
|
ShowUnitTestsPad(); |
||||||
|
ShowOutputPad(); |
||||||
|
|
||||||
|
UpdateUnitTestsPadToolbar(); |
||||||
|
ResetAllTestResultsInUnitTestsPad(); |
||||||
|
|
||||||
|
OnBeforeRunTests(); |
||||||
|
} |
||||||
|
|
||||||
|
void RunTests() |
||||||
|
{ |
||||||
|
if (IsBuildNeededBeforeTestRun()) { |
||||||
|
BuildProjectBeforeRunningTests(selectedTests); |
||||||
|
} else { |
||||||
|
context.SaveAllFilesCommand.SaveAllFiles(); |
||||||
|
RunTests(selectedTests); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool IsBuildNeededBeforeTestRun() |
||||||
|
{ |
||||||
|
return context.RegisteredTestFrameworks.IsBuildNeededBeforeTestRunForProject(selectedTests.Project); |
||||||
|
} |
||||||
|
|
||||||
|
void ClearTasks() |
||||||
|
{ |
||||||
|
context.TaskService.BuildMessageViewCategory.ClearText(); |
||||||
|
context.TaskService.InUpdate = true; |
||||||
|
context.TaskService.ClearExceptCommentTasks(); |
||||||
|
context.TaskService.InUpdate = false; |
||||||
|
} |
||||||
|
|
||||||
|
void ClearUnitTestCategoryText() |
||||||
|
{ |
||||||
|
context.UnitTestCategory.ClearText(); |
||||||
|
} |
||||||
|
|
||||||
|
void ShowUnitTestsPad() |
||||||
|
{ |
||||||
|
unitTestsPad.BringToFront(); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateUnitTestsPadToolbar() |
||||||
|
{ |
||||||
|
unitTestsPad.UpdateToolbar(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called before all tests are run. If multiple projects are
|
||||||
|
/// to be tested this is called only once.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnBeforeRunTests() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the tests after building the project under test.
|
||||||
|
/// </summary>
|
||||||
|
void BuildProjectBeforeRunningTests(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
BuildProjectBeforeTestRun build = CreateBuildProjectBeforeTestRun(selectedTests); |
||||||
|
build.BuildComplete += delegate { |
||||||
|
OnBuildComplete(build.LastBuildResults, selectedTests); |
||||||
|
}; |
||||||
|
build.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
BuildProjectBeforeTestRun CreateBuildProjectBeforeTestRun(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
return context.BuildProjectFactory.CreateBuildProjectBeforeTestRun(selectedTests.Project); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops running the tests.
|
||||||
|
/// </summary>
|
||||||
|
public void Stop() |
||||||
|
{ |
||||||
|
StopActiveTestRunner(); |
||||||
|
|
||||||
|
runningTestCommand = null; |
||||||
|
UpdateUnitTestsPadToolbar(); |
||||||
|
|
||||||
|
OnStop(); |
||||||
|
} |
||||||
|
|
||||||
|
void StopActiveTestRunner() |
||||||
|
{ |
||||||
|
if (testRunner != null) { |
||||||
|
testRunner.Stop(); |
||||||
|
testRunner.Dispose(); |
||||||
|
testRunner = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called after all tests have been run even if there have
|
||||||
|
/// been errors. If multiple projects are to be tested this is called only once.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnAfterRunTests() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void RunTests(NUnitConsoleApplication helper) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called by derived classes when a single test run
|
||||||
|
/// is finished.
|
||||||
|
/// </summary>
|
||||||
|
protected void TestRunCompleted() |
||||||
|
{ |
||||||
|
StopActiveTestRunner(); |
||||||
|
selectedTests.RemoveFirstProject(); |
||||||
|
if (selectedTests.HasProjects) { |
||||||
|
RunTests(); |
||||||
|
} else { |
||||||
|
runningTestCommand = null; |
||||||
|
UpdateUnitTestsPadToolbar(); |
||||||
|
ShowErrorList(); |
||||||
|
OnAfterRunTests(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void TestFinished(object source, TestFinishedEventArgs e) |
||||||
|
{ |
||||||
|
context.Workbench.SafeThreadAsyncCall(ShowResult, e.Result); |
||||||
|
} |
||||||
|
|
||||||
|
protected void ShowResult(TestResult result) |
||||||
|
{ |
||||||
|
if (IsTestResultFailureOrIsIgnored(result)) { |
||||||
|
AddTaskForTestResult(result); |
||||||
|
} |
||||||
|
UpdateTestResult(result); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsTestResultFailureOrIsIgnored(TestResult result) |
||||||
|
{ |
||||||
|
return result.IsFailure || result.IsIgnored; |
||||||
|
} |
||||||
|
|
||||||
|
void AddTaskForTestResult(TestResult testResult) |
||||||
|
{ |
||||||
|
TestProject project = GetTestProjectForProject(selectedTests.Project); |
||||||
|
Task task = TestResultTask.Create(testResult, project); |
||||||
|
context.TaskService.Add(task); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the test run should be stopped.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnStop() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void ShowOutputPad() |
||||||
|
{ |
||||||
|
ShowPad(context.Workbench.GetPad(typeof(CompilerMessageView))); |
||||||
|
} |
||||||
|
|
||||||
|
protected void ShowPad(PadDescriptor padDescriptor) |
||||||
|
{ |
||||||
|
context.Workbench.SafeThreadAsyncCall(padDescriptor.BringPadToFront); |
||||||
|
} |
||||||
|
|
||||||
|
void ShowErrorList() |
||||||
|
{ |
||||||
|
if (HasErrorsThatShouldBeDisplayed()) { |
||||||
|
ShowPad(context.Workbench.GetPad(typeof(ErrorListPad))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool HasErrorsThatShouldBeDisplayed() |
||||||
|
{ |
||||||
|
return context.TaskService.SomethingWentWrong && |
||||||
|
context.BuildOptions.ShowErrorListAfterBuild; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the test for the project after a successful build.
|
||||||
|
/// </summary>
|
||||||
|
void OnBuildComplete(BuildResults results, SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
if (BuildHasNoErrorsAndStillRunningTests(results)) { |
||||||
|
RunTests(selectedTests); |
||||||
|
} else { |
||||||
|
if (IsRunningTest) { |
||||||
|
Stop(); |
||||||
|
} |
||||||
|
ShowErrorList(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool BuildHasNoErrorsAndStillRunningTests(BuildResults results) |
||||||
|
{ |
||||||
|
return (results.ErrorCount == 0) && IsRunningTest; |
||||||
|
} |
||||||
|
|
||||||
|
void RunTests(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
testRunner = CreateTestRunner(selectedTests.Project); |
||||||
|
if (testRunner != null) { |
||||||
|
testRunner.MessageReceived += TestRunnerMessageReceived; |
||||||
|
testRunner.AllTestsFinished += AllTestsFinished; |
||||||
|
testRunner.TestFinished += TestFinished; |
||||||
|
testRunner.Start(selectedTests); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual ITestRunner CreateTestRunner(IProject project) |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
void TestRunnerMessageReceived(object source, MessageReceivedEventArgs e) |
||||||
|
{ |
||||||
|
context.UnitTestCategory.AppendLine(e.Message); |
||||||
|
} |
||||||
|
|
||||||
|
void AllTestsFinished(object source, EventArgs e) |
||||||
|
{ |
||||||
|
context.Workbench.SafeThreadAsyncCall(TestRunCompleted); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears the test results in the test tree view for all the
|
||||||
|
/// displayed projects.
|
||||||
|
/// </summary>
|
||||||
|
void ResetAllTestResultsInUnitTestsPad() |
||||||
|
{ |
||||||
|
unitTestsPad.ResetTestResults(); |
||||||
|
} |
||||||
|
|
||||||
|
TestProject GetTestProjectForProject(IProject project) |
||||||
|
{ |
||||||
|
return unitTestsPad.GetTestProject(project); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateTestResult(TestResult result) |
||||||
|
{ |
||||||
|
TestProject testProject = GetTestProjectForProject(selectedTests.Project); |
||||||
|
if (testProject != null) { |
||||||
|
testProject.UpdateTestResult(result); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.SharpDevelop.Project.Commands; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Custom build command that makes sure errors and warnings
|
||||||
|
/// are not cleared from the Errors list before every build since
|
||||||
|
/// we may be running multiple tests after each other.
|
||||||
|
/// </summary>
|
||||||
|
public class BuildProjectBeforeTestRun : BuildProjectBeforeExecute |
||||||
|
{ |
||||||
|
IUnitTestSaveAllFilesCommand saveAllFilesCommand; |
||||||
|
|
||||||
|
public BuildProjectBeforeTestRun(IProject targetProject, |
||||||
|
IUnitTestSaveAllFilesCommand saveAllFilesCommand) |
||||||
|
: base(targetProject) |
||||||
|
{ |
||||||
|
this.saveAllFilesCommand = saveAllFilesCommand; |
||||||
|
} |
||||||
|
|
||||||
|
public BuildProjectBeforeTestRun(IProject targetProject) |
||||||
|
: this(targetProject, new UnitTestSaveAllFilesCommand()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Before a build do not clear the tasks, just save any
|
||||||
|
/// dirty files.
|
||||||
|
/// </summary>
|
||||||
|
public override void BeforeBuild() |
||||||
|
{ |
||||||
|
saveAllFilesCommand.SaveAllFiles(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class EmptyUnitTestsPad : IUnitTestsPad |
||||||
|
{ |
||||||
|
public void UpdateToolbar() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void BringToFront() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void ResetTestResults() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public IProject[] GetProjects() |
||||||
|
{ |
||||||
|
return new IProject[0]; |
||||||
|
} |
||||||
|
|
||||||
|
public TestProject GetTestProject(IProject project) |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IAddInTree |
||||||
|
{ |
||||||
|
List<T> BuildItems<T>(string path, object caller); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IBuildOptions |
||||||
|
{ |
||||||
|
bool ShowErrorListAfterBuild { get; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IBuildProjectFactory |
||||||
|
{ |
||||||
|
BuildProjectBeforeTestRun CreateBuildProjectBeforeTestRun(IProject project); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IRegisteredTestFrameworks |
||||||
|
{ |
||||||
|
ITestFramework GetTestFrameworkForProject(IProject project); |
||||||
|
ITestRunner CreateTestRunner(IProject project); |
||||||
|
ITestRunner CreateTestDebugger(IProject project); |
||||||
|
|
||||||
|
bool IsTestMethod(IMember member); |
||||||
|
bool IsTestClass(IClass c); |
||||||
|
bool IsTestProject(IProject project); |
||||||
|
|
||||||
|
bool IsBuildNeededBeforeTestRunForProject(IProject project); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IRunTestCommandContext |
||||||
|
{ |
||||||
|
IRegisteredTestFrameworks RegisteredTestFrameworks { get; } |
||||||
|
IUnitTestTaskService TaskService { get; } |
||||||
|
IUnitTestWorkbench Workbench { get; } |
||||||
|
IBuildProjectFactory BuildProjectFactory { get; } |
||||||
|
IBuildOptions BuildOptions { get; } |
||||||
|
MessageViewCategory UnitTestCategory { get; } |
||||||
|
IUnitTestsPad OpenUnitTestsPad { get; } |
||||||
|
IUnitTestMessageService MessageService { get; } |
||||||
|
IUnitTestSaveAllFilesCommand SaveAllFilesCommand { get; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface ITestFrameworkFactory |
||||||
|
{ |
||||||
|
ITestFramework Create(string className); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface ITestResultsMonitor : IDisposable |
||||||
|
{ |
||||||
|
event TestFinishedEventHandler TestFinished; |
||||||
|
|
||||||
|
string FileName { get; set; } |
||||||
|
|
||||||
|
void Stop(); |
||||||
|
void Start(); |
||||||
|
void Read(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Util; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface ITestRunner : IDisposable |
||||||
|
{ |
||||||
|
event TestFinishedEventHandler TestFinished; |
||||||
|
event EventHandler AllTestsFinished; |
||||||
|
event MessageReceivedEventHandler MessageReceived; |
||||||
|
void Start(SelectedTests selectedTests); |
||||||
|
void Stop(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Data; |
||||||
|
using ICSharpCode.SharpDevelop.Debugging; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestDebuggerService |
||||||
|
{ |
||||||
|
bool IsDebuggerLoaded { get; } |
||||||
|
IDebugger CurrentDebugger { get; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestFileService |
||||||
|
{ |
||||||
|
void OpenFile(string fileName); |
||||||
|
|
||||||
|
void JumpToFilePosition(string fileName, int line, int column); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestMessageService |
||||||
|
{ |
||||||
|
bool AskQuestion(string question, string caption); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Util; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestProcessRunner |
||||||
|
{ |
||||||
|
bool LogStandardOutputAndError { get; set; } |
||||||
|
string WorkingDirectory { get; set; } |
||||||
|
|
||||||
|
void Start(string command, string arguments); |
||||||
|
void Kill(); |
||||||
|
|
||||||
|
event LineReceivedEventHandler OutputLineReceived; |
||||||
|
event LineReceivedEventHandler ErrorLineReceived; |
||||||
|
event EventHandler ProcessExited; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestSaveAllFilesCommand |
||||||
|
{ |
||||||
|
void SaveAllFiles(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestTaskService |
||||||
|
{ |
||||||
|
MessageViewCategory BuildMessageViewCategory { get; } |
||||||
|
bool InUpdate { get; set; } |
||||||
|
void ClearExceptCommentTasks(); |
||||||
|
void Add(Task task); |
||||||
|
bool SomethingWentWrong { get; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestWorkbench |
||||||
|
{ |
||||||
|
PadDescriptor GetPad(Type type); |
||||||
|
void SafeThreadAsyncCall(Action method); |
||||||
|
void SafeThreadAsyncCall<A>(Action<A> method, A arg1); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface IUnitTestsPad |
||||||
|
{ |
||||||
|
void UpdateToolbar(); |
||||||
|
void BringToFront(); |
||||||
|
void ResetTestResults(); |
||||||
|
IProject[] GetProjects(); |
||||||
|
TestProject GetTestProject(IProject project); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public delegate void MessageReceivedEventHandler(object sender, MessageReceivedEventArgs e); |
||||||
|
|
||||||
|
public class MessageReceivedEventArgs : EventArgs |
||||||
|
{ |
||||||
|
string message; |
||||||
|
|
||||||
|
public MessageReceivedEventArgs(string message) |
||||||
|
{ |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
public string Message { |
||||||
|
get { return message; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.SharpDevelop.Debugging; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class NUnitTestDebugger : TestDebuggerBase |
||||||
|
{ |
||||||
|
UnitTestingOptions options; |
||||||
|
|
||||||
|
public NUnitTestDebugger() |
||||||
|
: this(new UnitTestDebuggerService(), |
||||||
|
new UnitTestMessageService(), |
||||||
|
new TestResultsMonitor(), |
||||||
|
new UnitTestingOptions()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public NUnitTestDebugger(IUnitTestDebuggerService debuggerService, |
||||||
|
IUnitTestMessageService messageService, |
||||||
|
ITestResultsMonitor testResultsMonitor, |
||||||
|
UnitTestingOptions options) |
||||||
|
: base(debuggerService, messageService, testResultsMonitor) |
||||||
|
{ |
||||||
|
this.options = options; |
||||||
|
} |
||||||
|
|
||||||
|
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options); |
||||||
|
app.Results = base.TestResultsMonitor.FileName; |
||||||
|
return app.GetProcessStartInfo(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override TestResult CreateTestResultForTestFramework(TestResult testResult) |
||||||
|
{ |
||||||
|
return new NUnitTestResult(testResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,115 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class NUnitTestFramework : ITestFramework |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the project is a test project. A project
|
||||||
|
/// is considered to be a test project if it contains a reference
|
||||||
|
/// to the NUnit.Framework assembly.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTestProject(IProject project) |
||||||
|
{ |
||||||
|
if (project != null) { |
||||||
|
foreach (ProjectItem projectItem in project.Items) { |
||||||
|
ReferenceProjectItem referenceProjectItem = projectItem as ReferenceProjectItem; |
||||||
|
if (IsNUnitFrameworkAssemblyReference(referenceProjectItem)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
bool IsNUnitFrameworkAssemblyReference(ReferenceProjectItem referenceProjectItem) |
||||||
|
{ |
||||||
|
if (referenceProjectItem != null) { |
||||||
|
string name = referenceProjectItem.ShortName; |
||||||
|
return name.Equals("NUnit.Framework", StringComparison.OrdinalIgnoreCase); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the class is a test fixture. A class
|
||||||
|
/// is considered to be a test class if it contains a TestFixture attribute.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTestClass(IClass c) |
||||||
|
{ |
||||||
|
StringComparer nameComparer = GetNameComparer(c); |
||||||
|
if (nameComparer != null) { |
||||||
|
NUnitTestAttributeName testAttributeName = new NUnitTestAttributeName("TestFixture", nameComparer); |
||||||
|
foreach (IAttribute attribute in c.Attributes) { |
||||||
|
if (testAttributeName.IsEqual(attribute)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
StringComparer GetNameComparer(IClass c) |
||||||
|
{ |
||||||
|
if (c != null) { |
||||||
|
IProjectContent projectContent = c.ProjectContent; |
||||||
|
if (projectContent != null) { |
||||||
|
LanguageProperties language = projectContent.Language; |
||||||
|
if (language != null) { |
||||||
|
return language.NameComparer; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the method is a test method. A method
|
||||||
|
/// is considered to be a test method if it contains the NUnit Test attribute.
|
||||||
|
/// If the method has parameters it cannot be a test method.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTestMethod(IMember member) |
||||||
|
{ |
||||||
|
if (member == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
StringComparer nameComparer = GetNameComparer(member.DeclaringType); |
||||||
|
if (nameComparer != null) { |
||||||
|
NUnitTestAttributeName testAttribute = new NUnitTestAttributeName("Test", nameComparer); |
||||||
|
foreach (IAttribute attribute in member.Attributes) { |
||||||
|
if (testAttribute.IsEqual(attribute)) { |
||||||
|
IMethod method = (IMethod)member; |
||||||
|
if (method.Parameters.Count == 0) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsBuildNeededBeforeTestRun { |
||||||
|
get { return true; } |
||||||
|
} |
||||||
|
|
||||||
|
public ITestRunner CreateTestRunner() |
||||||
|
{ |
||||||
|
return new NUnitTestRunner(); |
||||||
|
} |
||||||
|
|
||||||
|
public ITestRunner CreateTestDebugger() |
||||||
|
{ |
||||||
|
return new NUnitTestDebugger(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class NUnitTestResult : TestResult |
||||||
|
{ |
||||||
|
public NUnitTestResult(TestResult testResult) |
||||||
|
: base(testResult.Name) |
||||||
|
{ |
||||||
|
Message = testResult.Message; |
||||||
|
ResultType = testResult.ResultType; |
||||||
|
StackTrace = testResult.StackTrace; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnStackTraceChanged() |
||||||
|
{ |
||||||
|
FileLineReference fileLineRef = OutputTextLineParser.GetNUnitOutputFileLineReference(StackTrace, true); |
||||||
|
if (fileLineRef != null) { |
||||||
|
StackTraceFilePosition = CreateFilePosition(fileLineRef); |
||||||
|
} else { |
||||||
|
StackTraceFilePosition = FilePosition.Empty; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
FilePosition CreateFilePosition(FileLineReference fileLineRef) |
||||||
|
{ |
||||||
|
string fileName = Path.GetFullPath(fileLineRef.FileName); |
||||||
|
return new FilePosition(fileName, fileLineRef.Line, fileLineRef.Column + 1); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.SharpDevelop.Util; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class NUnitTestRunner : TestProcessRunnerBase |
||||||
|
{ |
||||||
|
UnitTestingOptions options; |
||||||
|
|
||||||
|
public NUnitTestRunner() |
||||||
|
: this(new UnitTestProcessRunner(), |
||||||
|
new TestResultsMonitor(), |
||||||
|
new UnitTestingOptions()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public NUnitTestRunner(IUnitTestProcessRunner processRunner, |
||||||
|
ITestResultsMonitor testResultsMonitor, |
||||||
|
UnitTestingOptions options) |
||||||
|
: base(processRunner, testResultsMonitor) |
||||||
|
{ |
||||||
|
this.options = options; |
||||||
|
} |
||||||
|
|
||||||
|
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options); |
||||||
|
app.Results = base.TestResultsMonitor.FileName; |
||||||
|
return app.GetProcessStartInfo(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override TestResult CreateTestResultForTestFramework(TestResult testResult) |
||||||
|
{ |
||||||
|
return new NUnitTestResult(testResult); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,113 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class RegisteredTestFrameworks : IRegisteredTestFrameworks |
||||||
|
{ |
||||||
|
List<TestFrameworkDescriptor> testFrameworkDescriptors; |
||||||
|
public const string AddInPath = "/SharpDevelop/UnitTesting/TestFrameworks"; |
||||||
|
|
||||||
|
public RegisteredTestFrameworks(IAddInTree addInTree) |
||||||
|
{ |
||||||
|
testFrameworkDescriptors = addInTree.BuildItems<TestFrameworkDescriptor>(AddInPath, null); |
||||||
|
} |
||||||
|
|
||||||
|
public ITestFramework GetTestFrameworkForProject(IProject project) |
||||||
|
{ |
||||||
|
if (project != null) { |
||||||
|
foreach (TestFrameworkDescriptor descriptor in testFrameworkDescriptors) { |
||||||
|
if (descriptor.IsSupportedProject(project)) { |
||||||
|
return descriptor.TestFramework; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsTestMethod(IMember member) |
||||||
|
{ |
||||||
|
ITestFramework testFramework = GetTestFramework(member); |
||||||
|
if (testFramework != null) { |
||||||
|
return testFramework.IsTestMethod(member); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
ITestFramework GetTestFramework(IMember member) |
||||||
|
{ |
||||||
|
if (member != null) { |
||||||
|
return GetTestFramework(member.DeclaringType); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
ITestFramework GetTestFramework(IClass c) |
||||||
|
{ |
||||||
|
IProject project = GetProject(c); |
||||||
|
return GetTestFrameworkForProject(project); |
||||||
|
} |
||||||
|
|
||||||
|
IProject GetProject(IClass c) |
||||||
|
{ |
||||||
|
if (c != null) { |
||||||
|
return c.ProjectContent.Project as IProject; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsTestClass(IClass c) |
||||||
|
{ |
||||||
|
ITestFramework testFramework = GetTestFramework(c); |
||||||
|
if (testFramework != null) { |
||||||
|
return testFramework.IsTestClass(c); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsTestProject(IProject project) |
||||||
|
{ |
||||||
|
ITestFramework testFramework = GetTestFrameworkForProject(project); |
||||||
|
if (testFramework != null) { |
||||||
|
return testFramework.IsTestProject(project); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public ITestRunner CreateTestRunner(IProject project) |
||||||
|
{ |
||||||
|
ITestFramework testFramework = GetTestFrameworkForProject(project); |
||||||
|
if (testFramework != null) { |
||||||
|
return testFramework.CreateTestRunner(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public ITestRunner CreateTestDebugger(IProject project) |
||||||
|
{ |
||||||
|
ITestFramework testFramework = GetTestFrameworkForProject(project); |
||||||
|
if (testFramework != null) { |
||||||
|
return testFramework.CreateTestDebugger(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsBuildNeededBeforeTestRunForProject(IProject project) |
||||||
|
{ |
||||||
|
ITestFramework testFramework = GetTestFrameworkForProject(project); |
||||||
|
if (testFramework != null) { |
||||||
|
return testFramework.IsBuildNeededBeforeTestRun; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class RunAllTestsInPadCommand : RunTestInPadCommand |
||||||
|
{ |
||||||
|
public RunAllTestsInPadCommand() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public RunAllTestsInPadCommand(IRunTestCommandContext context) |
||||||
|
: base(context) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
// To make sure all tests are run we set the Owner to null.
|
||||||
|
Owner = null; |
||||||
|
base.Run(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class RunProjectTestsInPadCommand : RunTestInPadCommand, ITestTreeView |
||||||
|
{ |
||||||
|
public RunProjectTestsInPadCommand() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public RunProjectTestsInPadCommand(IRunTestCommandContext context) |
||||||
|
: base(context) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
Owner = this; |
||||||
|
base.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
public IMember SelectedMethod { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
|
||||||
|
public IClass SelectedClass { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
|
||||||
|
public IProject SelectedProject { |
||||||
|
get { return ProjectService.CurrentProject; } |
||||||
|
} |
||||||
|
|
||||||
|
public string SelectedNamespace { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,61 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class RunTestCommandContext : IRunTestCommandContext |
||||||
|
{ |
||||||
|
UnitTestingOptions options = new UnitTestingOptions(); |
||||||
|
IRegisteredTestFrameworks testFrameworks = TestService.RegisteredTestFrameworks; |
||||||
|
UnitTestTaskService taskService = new UnitTestTaskService(); |
||||||
|
UnitTestWorkbench workbench = new UnitTestWorkbench(); |
||||||
|
UnitTestBuildProjectFactory buildProjectFactory = new UnitTestBuildProjectFactory(); |
||||||
|
UnitTestBuildOptions buildOptions = new UnitTestBuildOptions(); |
||||||
|
MessageViewCategory unitTestCategory = TestService.UnitTestMessageView; |
||||||
|
UnitTestMessageService messageService = new UnitTestMessageService(); |
||||||
|
UnitTestSaveAllFilesCommand saveAllFilesCommand = new UnitTestSaveAllFilesCommand(); |
||||||
|
|
||||||
|
public IRegisteredTestFrameworks RegisteredTestFrameworks { |
||||||
|
get { return testFrameworks; } |
||||||
|
} |
||||||
|
|
||||||
|
public IUnitTestTaskService TaskService { |
||||||
|
get { return taskService; } |
||||||
|
} |
||||||
|
|
||||||
|
public IUnitTestWorkbench Workbench { |
||||||
|
get { return workbench; } |
||||||
|
} |
||||||
|
|
||||||
|
public IBuildProjectFactory BuildProjectFactory { |
||||||
|
get { return buildProjectFactory; } |
||||||
|
} |
||||||
|
|
||||||
|
public IBuildOptions BuildOptions { |
||||||
|
get { return buildOptions; } |
||||||
|
} |
||||||
|
|
||||||
|
public MessageViewCategory UnitTestCategory { |
||||||
|
get { return unitTestCategory; } |
||||||
|
} |
||||||
|
|
||||||
|
public IUnitTestsPad OpenUnitTestsPad { |
||||||
|
get { return UnitTestsPad.Instance; } |
||||||
|
} |
||||||
|
|
||||||
|
public IUnitTestMessageService MessageService { |
||||||
|
get { return messageService; } |
||||||
|
} |
||||||
|
|
||||||
|
public IUnitTestSaveAllFilesCommand SaveAllFilesCommand { |
||||||
|
get { return saveAllFilesCommand; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,550 +0,0 @@ |
|||||||
// <file>
|
|
||||||
// <copyright see="prj:///doc/copyright.txt"/>
|
|
||||||
// <license see="prj:///doc/license.txt"/>
|
|
||||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
|
||||||
// <version>$Revision$</version>
|
|
||||||
// </file>
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.IO; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop; |
|
||||||
using ICSharpCode.SharpDevelop.Commands; |
|
||||||
using ICSharpCode.SharpDevelop.Debugging; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using ICSharpCode.SharpDevelop.Gui; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
using ICSharpCode.SharpDevelop.Project.Commands; |
|
||||||
using ICSharpCode.SharpDevelop.Util; |
|
||||||
|
|
||||||
namespace ICSharpCode.UnitTesting |
|
||||||
{ |
|
||||||
public abstract class AbstractRunTestCommand : AbstractMenuCommand |
|
||||||
{ |
|
||||||
static MessageViewCategory testRunnerCategory; |
|
||||||
static AbstractRunTestCommand runningTestCommand; |
|
||||||
List<IProject> projects; |
|
||||||
IProject currentProject; |
|
||||||
TestResultsMonitor testResultsMonitor; |
|
||||||
|
|
||||||
public AbstractRunTestCommand() |
|
||||||
{ |
|
||||||
testResultsMonitor = new TestResultsMonitor(); |
|
||||||
testResultsMonitor.TestFinished += TestFinished; |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the running test command.
|
|
||||||
/// </summary>
|
|
||||||
public static AbstractRunTestCommand RunningTestCommand { |
|
||||||
get { |
|
||||||
return runningTestCommand; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether a test is currently running.
|
|
||||||
/// </summary>
|
|
||||||
public static bool IsRunningTest { |
|
||||||
get { |
|
||||||
return runningTestCommand != null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override void Run() |
|
||||||
{ |
|
||||||
projects = new List<IProject>(); |
|
||||||
|
|
||||||
IMember m = TestableCondition.GetMember(Owner); |
|
||||||
IClass c = (m != null) ? m.DeclaringType : TestableCondition.GetClass(Owner); |
|
||||||
IProject project = TestableCondition.GetProject(Owner); |
|
||||||
string namespaceFilter = TestableCondition.GetNamespace(Owner); |
|
||||||
|
|
||||||
if (project != null) { |
|
||||||
projects.Add(project); |
|
||||||
} else if (UnitTestsPad.Instance != null) { |
|
||||||
projects.AddRange(UnitTestsPad.Instance.TestTreeView.GetProjects()); |
|
||||||
} |
|
||||||
|
|
||||||
if (projects.Count > 0) { |
|
||||||
runningTestCommand = this; |
|
||||||
try { |
|
||||||
BeforeRun(); |
|
||||||
if (IsRunningTest) { |
|
||||||
currentProject = projects[0]; |
|
||||||
Run(currentProject, namespaceFilter, c, m); |
|
||||||
} |
|
||||||
} catch { |
|
||||||
runningTestCommand = null; |
|
||||||
throw; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static MessageViewCategory TestRunnerCategory { |
|
||||||
get { |
|
||||||
if (testRunnerCategory == null) { |
|
||||||
MessageViewCategory.Create(ref testRunnerCategory, "UnitTesting", "${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}"); |
|
||||||
} |
|
||||||
return testRunnerCategory; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Stops running the tests.
|
|
||||||
/// </summary>
|
|
||||||
public void Stop() |
|
||||||
{ |
|
||||||
runningTestCommand = null; |
|
||||||
UpdateUnitTestsPadToolbar(); |
|
||||||
|
|
||||||
projects.Clear(); |
|
||||||
|
|
||||||
testResultsMonitor.Stop(); |
|
||||||
StopMonitoring(); |
|
||||||
|
|
||||||
OnStop(); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called before all tests are run. If multiple projects are
|
|
||||||
/// to be tested this is called only once.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual void OnBeforeRunTests() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called after all tests have been run even if there have
|
|
||||||
/// been errors. If multiple projects are to be tested this is called only once.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual void OnAfterRunTests() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
protected abstract void RunTests(UnitTestApplicationStartHelper helper); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called by derived classes when a single test run
|
|
||||||
/// is finished.
|
|
||||||
/// </summary>
|
|
||||||
protected void TestsFinished() |
|
||||||
{ |
|
||||||
WorkbenchSingleton.AssertMainThread(); |
|
||||||
|
|
||||||
// Read the rest of the file just in case.
|
|
||||||
testResultsMonitor.Stop(); |
|
||||||
testResultsMonitor.Read(); |
|
||||||
StopMonitoring(); |
|
||||||
|
|
||||||
projects.Remove(currentProject); |
|
||||||
if (projects.Count > 0) { |
|
||||||
currentProject = projects[0]; |
|
||||||
Run(currentProject, null, null, null); |
|
||||||
} else { |
|
||||||
runningTestCommand = null; |
|
||||||
UpdateUnitTestsPadToolbar(); |
|
||||||
if (TaskService.SomethingWentWrong && ErrorListPad.ShowAfterBuild) { |
|
||||||
ShowErrorList(); |
|
||||||
} |
|
||||||
OnAfterRunTests(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called by derived classes to show a single test result.
|
|
||||||
/// </summary>
|
|
||||||
protected void ShowResult(TestResult result) |
|
||||||
{ |
|
||||||
if (result.IsFailure || result.IsIgnored) { |
|
||||||
TaskService.Add(CreateTask(result)); |
|
||||||
} |
|
||||||
UpdateTestResult(result); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the test run should be stopped.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual void OnStop() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Brings the specified pad to the front.
|
|
||||||
/// </summary>
|
|
||||||
protected void ShowPad(PadDescriptor padDescriptor) |
|
||||||
{ |
|
||||||
if (padDescriptor != null) { |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(padDescriptor.BringPadToFront); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs the tests after building the project under test.
|
|
||||||
/// </summary>
|
|
||||||
void Run(IProject project, string namespaceFilter, IClass fixture, IMember test) |
|
||||||
{ |
|
||||||
BuildProjectBeforeTestRun build = new BuildProjectBeforeTestRun(project); |
|
||||||
build.BuildComplete += delegate { |
|
||||||
OnBuildComplete(build.LastBuildResults, project, namespaceFilter, fixture, test); |
|
||||||
}; |
|
||||||
build.Run(); |
|
||||||
} |
|
||||||
|
|
||||||
void ShowUnitTestsPad() |
|
||||||
{ |
|
||||||
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(UnitTestsPad))); |
|
||||||
} |
|
||||||
|
|
||||||
void UpdateUnitTestsPadToolbar() |
|
||||||
{ |
|
||||||
if (UnitTestsPad.Instance != null) { |
|
||||||
UnitTestsPad.Instance.UpdateToolbar(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the initial workbench state before starting
|
|
||||||
/// a test run.
|
|
||||||
/// </summary>
|
|
||||||
void BeforeRun() |
|
||||||
{ |
|
||||||
TaskService.BuildMessageViewCategory.ClearText(); |
|
||||||
TaskService.InUpdate = true; |
|
||||||
TaskService.ClearExceptCommentTasks(); |
|
||||||
TaskService.InUpdate = false; |
|
||||||
|
|
||||||
TestRunnerCategory.ClearText(); |
|
||||||
|
|
||||||
ShowUnitTestsPad(); |
|
||||||
ShowOutputPad(); |
|
||||||
|
|
||||||
UpdateUnitTestsPadToolbar(); |
|
||||||
ResetAllTestResults(); |
|
||||||
|
|
||||||
OnBeforeRunTests(); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Brings output pad to the front.
|
|
||||||
/// </summary>
|
|
||||||
void ShowOutputPad() |
|
||||||
{ |
|
||||||
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView))); |
|
||||||
} |
|
||||||
|
|
||||||
Task CreateTask(TestResult result) |
|
||||||
{ |
|
||||||
TaskType taskType = TaskType.Warning; |
|
||||||
FileLineReference lineRef = null; |
|
||||||
string message = String.Empty; |
|
||||||
|
|
||||||
if (result.IsFailure) { |
|
||||||
taskType = TaskType.Error; |
|
||||||
lineRef = OutputTextLineParser.GetNUnitOutputFileLineReference(result.StackTrace, true); |
|
||||||
message = GetTestResultMessage(result, "${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}"); |
|
||||||
} else if (result.IsIgnored) { |
|
||||||
message = GetTestResultMessage(result, "${res:NUnitPad.NUnitPadContent.TestTreeView.TestNotExecutedMessage}"); |
|
||||||
} |
|
||||||
if (lineRef == null) { |
|
||||||
lineRef = FindTest(result.Name); |
|
||||||
} |
|
||||||
if (lineRef != null) { |
|
||||||
return new Task(FileName.Create(lineRef.FileName), |
|
||||||
message, lineRef.Column, lineRef.Line, taskType); |
|
||||||
} |
|
||||||
return new Task(null, message, 0, 0, taskType); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the test result message if there is on otherwise
|
|
||||||
/// uses the string resource to create a message.
|
|
||||||
/// </summary>
|
|
||||||
string GetTestResultMessage(TestResult result, string stringResource) |
|
||||||
{ |
|
||||||
if (result.Message.Length > 0) { |
|
||||||
return result.Message; |
|
||||||
} |
|
||||||
return StringParser.Parse(stringResource, new string[,] {{"TestCase", result.Name}}); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the location of the specified test method in the
|
|
||||||
/// project being tested.
|
|
||||||
/// </summary>
|
|
||||||
FileLineReference FindTest(string methodName) |
|
||||||
{ |
|
||||||
TestProject testProject = GetTestProject(currentProject); |
|
||||||
if (testProject != null) { |
|
||||||
TestMethod method = testProject.TestClasses.GetTestMethod(methodName); |
|
||||||
if (method != null) { |
|
||||||
MemberResolveResult resolveResult = new MemberResolveResult(null, null, method.Method); |
|
||||||
FilePosition filePos = resolveResult.GetDefinitionPosition(); |
|
||||||
return new FileLineReference(filePos.FileName, filePos.Line, filePos.Column); |
|
||||||
} |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
void ShowErrorList() |
|
||||||
{ |
|
||||||
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad))); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs the test for the project after a successful build.
|
|
||||||
/// </summary>
|
|
||||||
void OnBuildComplete(BuildResults results, IProject project, string namespaceFilter, IClass fixture, IMember test) |
|
||||||
{ |
|
||||||
if (results.ErrorCount == 0 && IsRunningTest) { |
|
||||||
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper(); |
|
||||||
|
|
||||||
UnitTestingOptions options = new UnitTestingOptions(); |
|
||||||
helper.NoThread = options.NoThread; |
|
||||||
helper.NoLogo = options.NoLogo; |
|
||||||
helper.NoDots = options.NoDots; |
|
||||||
helper.Labels = options.Labels; |
|
||||||
helper.ShadowCopy = !options.NoShadow; |
|
||||||
|
|
||||||
if (options.CreateXmlOutputFile) { |
|
||||||
helper.XmlOutputFile = Path.Combine(Path.GetDirectoryName(project.OutputAssemblyFullPath), project.AssemblyName + "-TestResult.xml"); |
|
||||||
} |
|
||||||
|
|
||||||
helper.Initialize(project, namespaceFilter, fixture, test); |
|
||||||
helper.Results = Path.GetTempFileName(); |
|
||||||
|
|
||||||
ResetTestResults(project); |
|
||||||
|
|
||||||
testResultsMonitor.FileName = helper.Results; |
|
||||||
testResultsMonitor.Start(); |
|
||||||
|
|
||||||
try { |
|
||||||
RunTests(helper); |
|
||||||
} catch { |
|
||||||
StopMonitoring(); |
|
||||||
throw; |
|
||||||
} |
|
||||||
} else { |
|
||||||
if (IsRunningTest) { |
|
||||||
Stop(); |
|
||||||
} |
|
||||||
if (TaskService.SomethingWentWrong && ErrorListPad.ShowAfterBuild) { |
|
||||||
ShowErrorList(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clears the test results in the test tree view for the
|
|
||||||
/// project currently being tested.
|
|
||||||
/// </summary>
|
|
||||||
void ResetTestResults(IProject project) |
|
||||||
{ |
|
||||||
TestProject testProject = GetTestProject(project); |
|
||||||
if (testProject != null) { |
|
||||||
testProject.ResetTestResults(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clears the test results in the test tree view for all the
|
|
||||||
/// displayed projects.
|
|
||||||
/// </summary>
|
|
||||||
void ResetAllTestResults() |
|
||||||
{ |
|
||||||
if (UnitTestsPad.Instance != null) { |
|
||||||
UnitTestsPad.Instance.TestTreeView.ResetTestResults(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the TestProject associated with the specified project
|
|
||||||
/// from the test tree view.
|
|
||||||
/// </summary>
|
|
||||||
TestProject GetTestProject(IProject project) |
|
||||||
{ |
|
||||||
if (UnitTestsPad.Instance != null) { |
|
||||||
return UnitTestsPad.Instance.TestTreeView.GetTestProject(project); |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates the test result in the test tree view.
|
|
||||||
/// </summary>
|
|
||||||
void UpdateTestResult(TestResult result) |
|
||||||
{ |
|
||||||
TestProject testProject = GetTestProject(currentProject); |
|
||||||
if (testProject != null) { |
|
||||||
testProject.UpdateTestResult(result); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void StopMonitoring() |
|
||||||
{ |
|
||||||
try { |
|
||||||
File.Delete(testResultsMonitor.FileName); |
|
||||||
} catch { } |
|
||||||
|
|
||||||
testResultsMonitor.Dispose(); |
|
||||||
} |
|
||||||
|
|
||||||
void TestFinished(object source, TestFinishedEventArgs e) |
|
||||||
{ |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(ShowResult, e.Result); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Custom build command that makes sure errors and warnings
|
|
||||||
/// are not cleared from the Errors list before every build since
|
|
||||||
/// we may be running multiple tests after each other.
|
|
||||||
/// </summary>
|
|
||||||
public class BuildProjectBeforeTestRun : BuildProjectBeforeExecute |
|
||||||
{ |
|
||||||
public BuildProjectBeforeTestRun(IProject targetProject) |
|
||||||
: base(targetProject) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Before a build do not clear the tasks, just save any
|
|
||||||
/// dirty files.
|
|
||||||
/// </summary>
|
|
||||||
public override void BeforeBuild() |
|
||||||
{ |
|
||||||
SaveAllFiles.SaveAll(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class RunTestInPadCommand : AbstractRunTestCommand |
|
||||||
{ |
|
||||||
ProcessRunner runner; |
|
||||||
|
|
||||||
public RunTestInPadCommand() |
|
||||||
{ |
|
||||||
runner = new ProcessRunner(); |
|
||||||
runner.LogStandardOutputAndError = false; |
|
||||||
runner.OutputLineReceived += OutputLineReceived; |
|
||||||
runner.ProcessExited += ProcessExited; |
|
||||||
} |
|
||||||
|
|
||||||
protected override void RunTests(UnitTestApplicationStartHelper helper) |
|
||||||
{ |
|
||||||
TestRunnerCategory.AppendLine(helper.GetCommandLine()); |
|
||||||
runner.Start(helper.UnitTestApplication, helper.GetArguments()); |
|
||||||
} |
|
||||||
|
|
||||||
protected override void OnStop() |
|
||||||
{ |
|
||||||
runner.Kill(); |
|
||||||
} |
|
||||||
|
|
||||||
protected ProcessRunner GetProcessRunner() |
|
||||||
{ |
|
||||||
return runner; |
|
||||||
} |
|
||||||
|
|
||||||
void OutputLineReceived(object source, LineReceivedEventArgs e) |
|
||||||
{ |
|
||||||
TestRunnerCategory.AppendLine(e.Line); |
|
||||||
} |
|
||||||
|
|
||||||
void ProcessExited(object source, EventArgs e) |
|
||||||
{ |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished); |
|
||||||
} |
|
||||||
|
|
||||||
void TestFinished(object source, TestFinishedEventArgs e) |
|
||||||
{ |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(ShowResult, e.Result); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class RunTestWithDebuggerCommand : AbstractRunTestCommand |
|
||||||
{ |
|
||||||
public override void Run() |
|
||||||
{ |
|
||||||
if (DebuggerService.IsDebuggerLoaded && DebuggerService.CurrentDebugger.IsDebugging) { |
|
||||||
if (MessageService.AskQuestion("${res:XML.MainMenu.RunMenu.Compile.StopDebuggingQuestion}", |
|
||||||
"${res:XML.MainMenu.RunMenu.Compile.StopDebuggingTitle}")) |
|
||||||
{ |
|
||||||
DebuggerService.CurrentDebugger.Stop(); |
|
||||||
base.Run(); |
|
||||||
} |
|
||||||
} else { |
|
||||||
base.Run(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected override void RunTests(UnitTestApplicationStartHelper helper) |
|
||||||
{ |
|
||||||
bool running = false; |
|
||||||
|
|
||||||
try { |
|
||||||
TestRunnerCategory.AppendLine(helper.GetCommandLine()); |
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo(helper.UnitTestApplication); |
|
||||||
startInfo.Arguments = helper.GetArguments(); |
|
||||||
startInfo.WorkingDirectory = UnitTestApplicationStartHelper.UnitTestApplicationDirectory; |
|
||||||
DebuggerService.DebugStopped += DebuggerFinished; |
|
||||||
DebuggerService.CurrentDebugger.Start(startInfo); |
|
||||||
running = true; |
|
||||||
} finally { |
|
||||||
if (!running) { |
|
||||||
DebuggerService.DebugStopped -= DebuggerFinished; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected override void OnStop() |
|
||||||
{ |
|
||||||
if (DebuggerService.CurrentDebugger.IsDebugging) { |
|
||||||
DebuggerService.CurrentDebugger.Stop(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DebuggerFinished(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
DebuggerService.DebugStopped -= DebuggerFinished; |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class RunAllTestsInPadCommand : RunTestInPadCommand |
|
||||||
{ |
|
||||||
public override void Run() |
|
||||||
{ |
|
||||||
// To make sure all tests are run we set the Owner to null.
|
|
||||||
Owner = null; |
|
||||||
base.Run(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class RunProjectTestsInPadCommand : RunTestInPadCommand, ITestTreeView |
|
||||||
{ |
|
||||||
public override void Run() |
|
||||||
{ |
|
||||||
Owner = this; |
|
||||||
base.Run(); |
|
||||||
} |
|
||||||
|
|
||||||
public IMember SelectedMethod { |
|
||||||
get { return null; } |
|
||||||
} |
|
||||||
|
|
||||||
public IClass SelectedClass { |
|
||||||
get { return null; } |
|
||||||
} |
|
||||||
|
|
||||||
public IProject SelectedProject { |
|
||||||
get { return ProjectService.CurrentProject; } |
|
||||||
} |
|
||||||
|
|
||||||
public string SelectedNamespace { |
|
||||||
get { return null; } |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,30 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.SharpDevelop.Util; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class RunTestInPadCommand : AbstractRunTestCommand |
||||||
|
{ |
||||||
|
public RunTestInPadCommand() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public RunTestInPadCommand(IRunTestCommandContext context) |
||||||
|
: base(context) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected override ITestRunner CreateTestRunner(IProject project) |
||||||
|
{ |
||||||
|
return Context.RegisteredTestFrameworks.CreateTestRunner(project); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class RunTestWithDebuggerCommand : AbstractRunTestCommand |
||||||
|
{ |
||||||
|
public RunTestWithDebuggerCommand() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public RunTestWithDebuggerCommand(IRunTestCommandContext context) |
||||||
|
: base(context) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected override ITestRunner CreateTestRunner(IProject project) |
||||||
|
{ |
||||||
|
return Context.RegisteredTestFrameworks.CreateTestDebugger(project); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class SelectedTests |
||||||
|
{ |
||||||
|
string namespaceFilter; |
||||||
|
IClass c; |
||||||
|
IMember method; |
||||||
|
List<IProject> projects = new List<IProject>(); |
||||||
|
|
||||||
|
public SelectedTests(IProject project, string namespaceFilter, IClass c, IMember method) |
||||||
|
{ |
||||||
|
this.namespaceFilter = namespaceFilter; |
||||||
|
this.c = c; |
||||||
|
this.method = method; |
||||||
|
|
||||||
|
if (project != null) { |
||||||
|
projects.Add(project); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public SelectedTests(IProject project) |
||||||
|
: this(project, null, null, null) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public SelectedTests(object owner, IProject[] selectedProjects) |
||||||
|
{ |
||||||
|
IProject project = TestableCondition.GetProject(owner); |
||||||
|
if (project != null) { |
||||||
|
projects.Add(project); |
||||||
|
} else { |
||||||
|
projects.AddRange(selectedProjects); |
||||||
|
} |
||||||
|
|
||||||
|
method = TestableCondition.GetMember(owner); |
||||||
|
c = GetClass(method, owner); |
||||||
|
namespaceFilter = TestableCondition.GetNamespace(owner); |
||||||
|
} |
||||||
|
|
||||||
|
static IClass GetClass(IMember member, Object owner) |
||||||
|
{ |
||||||
|
if (member != null) { |
||||||
|
return member.DeclaringType; |
||||||
|
} |
||||||
|
return TestableCondition.GetClass(owner); |
||||||
|
} |
||||||
|
|
||||||
|
public bool HasProjects { |
||||||
|
get { return projects.Count > 0; } |
||||||
|
} |
||||||
|
|
||||||
|
public void RemoveFirstProject() |
||||||
|
{ |
||||||
|
if (HasProjects) { |
||||||
|
projects.RemoveAt(0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public IList<IProject> Projects { |
||||||
|
get { return projects; } |
||||||
|
} |
||||||
|
|
||||||
|
public IProject Project { |
||||||
|
get { |
||||||
|
if (projects.Count > 0) { |
||||||
|
return projects[0]; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string NamespaceFilter { |
||||||
|
get { return namespaceFilter; } |
||||||
|
} |
||||||
|
|
||||||
|
public IClass Class { |
||||||
|
get { return c; } |
||||||
|
} |
||||||
|
|
||||||
|
public IMember Method { |
||||||
|
get { return method; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,112 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.SharpDevelop.Debugging; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public abstract class TestDebuggerBase : TestRunnerBase |
||||||
|
{ |
||||||
|
IUnitTestDebuggerService debuggerService; |
||||||
|
IUnitTestMessageService messageService; |
||||||
|
IDebugger debugger; |
||||||
|
ITestResultsMonitor testResultsMonitor; |
||||||
|
|
||||||
|
public TestDebuggerBase() |
||||||
|
: this(new UnitTestDebuggerService(), |
||||||
|
new UnitTestMessageService(), |
||||||
|
new TestResultsMonitor()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public TestDebuggerBase(IUnitTestDebuggerService debuggerService, |
||||||
|
IUnitTestMessageService messageService, |
||||||
|
ITestResultsMonitor testResultsMonitor) |
||||||
|
{ |
||||||
|
this.debuggerService = debuggerService; |
||||||
|
this.messageService = messageService; |
||||||
|
this.testResultsMonitor = testResultsMonitor; |
||||||
|
this.debugger = debuggerService.CurrentDebugger; |
||||||
|
|
||||||
|
testResultsMonitor.TestFinished += OnTestFinished; |
||||||
|
} |
||||||
|
|
||||||
|
protected ITestResultsMonitor TestResultsMonitor { |
||||||
|
get { return testResultsMonitor; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Start(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests); |
||||||
|
if (IsDebuggerRunning) { |
||||||
|
if (CanStopDebugging()) { |
||||||
|
debugger.Stop(); |
||||||
|
Start(startInfo); |
||||||
|
} |
||||||
|
} else { |
||||||
|
Start(startInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsDebuggerRunning { |
||||||
|
get { return debuggerService.IsDebuggerLoaded && debugger.IsDebugging; } |
||||||
|
} |
||||||
|
|
||||||
|
bool CanStopDebugging() |
||||||
|
{ |
||||||
|
string question = "${res:XML.MainMenu.RunMenu.Compile.StopDebuggingQuestion}"; |
||||||
|
string caption = "${res:XML.MainMenu.RunMenu.Compile.StopDebuggingTitle}"; |
||||||
|
return messageService.AskQuestion(question, caption); |
||||||
|
} |
||||||
|
|
||||||
|
void Start(ProcessStartInfo startInfo) |
||||||
|
{ |
||||||
|
testResultsMonitor.Start(); |
||||||
|
StartDebugger(startInfo); |
||||||
|
} |
||||||
|
|
||||||
|
void StartDebugger(ProcessStartInfo startInfo) |
||||||
|
{ |
||||||
|
LogCommandLine(startInfo); |
||||||
|
|
||||||
|
bool running = false; |
||||||
|
debugger.DebugStopped += DebugStopped; |
||||||
|
try { |
||||||
|
debugger.Start(startInfo); |
||||||
|
running = true; |
||||||
|
} finally { |
||||||
|
if (!running) { |
||||||
|
debugger.DebugStopped -= DebugStopped; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void DebugStopped(object source, EventArgs e) |
||||||
|
{ |
||||||
|
debugger.DebugStopped -= DebugStopped; |
||||||
|
OnAllTestsFinished(source, e); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Stop() |
||||||
|
{ |
||||||
|
if (debugger.IsDebugging) { |
||||||
|
debugger.Stop(); |
||||||
|
} |
||||||
|
|
||||||
|
testResultsMonitor.Stop(); |
||||||
|
testResultsMonitor.Read(); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Dispose() |
||||||
|
{ |
||||||
|
Stop(); |
||||||
|
testResultsMonitor.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public interface ITestFramework |
||||||
|
{ |
||||||
|
bool IsTestMethod(IMember member); |
||||||
|
bool IsTestClass(IClass c); |
||||||
|
bool IsTestProject(IProject project); |
||||||
|
|
||||||
|
ITestRunner CreateTestRunner(); |
||||||
|
ITestRunner CreateTestDebugger(); |
||||||
|
|
||||||
|
bool IsBuildNeededBeforeTestRun { get; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,81 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class TestFrameworkDescriptor |
||||||
|
{ |
||||||
|
Properties properties; |
||||||
|
ITestFrameworkFactory factory; |
||||||
|
ITestFramework testFramework; |
||||||
|
List<string> supportedProjectFileExtensions = new List<string>(); |
||||||
|
|
||||||
|
public TestFrameworkDescriptor(Properties properties, ITestFrameworkFactory factory) |
||||||
|
{ |
||||||
|
this.properties = properties; |
||||||
|
this.factory = factory; |
||||||
|
|
||||||
|
GetSupportedProjectFileExtensions(); |
||||||
|
} |
||||||
|
|
||||||
|
void GetSupportedProjectFileExtensions() |
||||||
|
{ |
||||||
|
string extensions = properties["supportedProjects"]; |
||||||
|
|
||||||
|
foreach (string extension in extensions.Split(';')) { |
||||||
|
supportedProjectFileExtensions.Add(extension.ToLowerInvariant().Trim()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Id { |
||||||
|
get { return properties["id"]; } |
||||||
|
} |
||||||
|
|
||||||
|
public ITestFramework TestFramework { |
||||||
|
get { |
||||||
|
CreateTestFrameworkIfNotCreated(); |
||||||
|
return testFramework; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CreateTestFrameworkIfNotCreated() |
||||||
|
{ |
||||||
|
if (testFramework == null) { |
||||||
|
testFramework = factory.Create(ClassName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
string ClassName { |
||||||
|
get { return properties["class"]; } |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsSupportedProject(IProject project) |
||||||
|
{ |
||||||
|
string extension = GetProjectFileExtension(project); |
||||||
|
return IsSupportedProjectFileExtension(extension); |
||||||
|
} |
||||||
|
|
||||||
|
string GetProjectFileExtension(IProject project) |
||||||
|
{ |
||||||
|
if (project != null) { |
||||||
|
return Path.GetExtension(project.FileName).ToLowerInvariant(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
bool IsSupportedProjectFileExtension(string extension) |
||||||
|
{ |
||||||
|
return supportedProjectFileExtensions.Contains(extension); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class TestFrameworkDoozer : IDoozer |
||||||
|
{ |
||||||
|
public TestFrameworkDoozer() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public bool HandleConditions { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
|
||||||
|
public object BuildItem(object caller, Codon codon, ArrayList subItems) |
||||||
|
{ |
||||||
|
return BuildItem(codon, new TestFrameworkFactory(codon.AddIn)); |
||||||
|
} |
||||||
|
|
||||||
|
public TestFrameworkDescriptor BuildItem(Codon codon, ITestFrameworkFactory factory) |
||||||
|
{ |
||||||
|
return new TestFrameworkDescriptor(codon.Properties, factory); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class TestFrameworkFactory : ITestFrameworkFactory |
||||||
|
{ |
||||||
|
AddIn addin; |
||||||
|
|
||||||
|
public TestFrameworkFactory(AddIn addin) |
||||||
|
{ |
||||||
|
this.addin = addin; |
||||||
|
} |
||||||
|
|
||||||
|
public ITestFramework Create(string className) |
||||||
|
{ |
||||||
|
return addin.CreateObject(className) as ITestFramework; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.SharpDevelop.Util; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class TestProcessRunnerBase : TestRunnerBase |
||||||
|
{ |
||||||
|
IUnitTestProcessRunner processRunner; |
||||||
|
ITestResultsMonitor testResultsMonitor; |
||||||
|
|
||||||
|
public TestProcessRunnerBase() |
||||||
|
: this(new UnitTestProcessRunner(), |
||||||
|
new TestResultsMonitor()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public TestProcessRunnerBase(IUnitTestProcessRunner processRunner, |
||||||
|
ITestResultsMonitor testResultsMonitor) |
||||||
|
{ |
||||||
|
this.processRunner = processRunner; |
||||||
|
this.testResultsMonitor = testResultsMonitor; |
||||||
|
|
||||||
|
processRunner.LogStandardOutputAndError = false; |
||||||
|
processRunner.OutputLineReceived += OutputLineReceived; |
||||||
|
processRunner.ErrorLineReceived += OutputLineReceived; |
||||||
|
processRunner.ProcessExited += OnAllTestsFinished; |
||||||
|
testResultsMonitor.TestFinished += OnTestFinished; |
||||||
|
} |
||||||
|
|
||||||
|
protected ITestResultsMonitor TestResultsMonitor { |
||||||
|
get { return testResultsMonitor; } |
||||||
|
} |
||||||
|
|
||||||
|
// public override event EventHandler AllTestsFinished {
|
||||||
|
// add { processRunner.ProcessExited += value; }
|
||||||
|
// remove { processRunner.ProcessExited -= value; }
|
||||||
|
// }
|
||||||
|
|
||||||
|
void OutputLineReceived(object source, LineReceivedEventArgs e) |
||||||
|
{ |
||||||
|
OnMessageReceived(e.Line); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Start(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests); |
||||||
|
Start(startInfo); |
||||||
|
} |
||||||
|
|
||||||
|
void Start(ProcessStartInfo processStartInfo) |
||||||
|
{ |
||||||
|
LogCommandLine(processStartInfo); |
||||||
|
|
||||||
|
testResultsMonitor.Start(); |
||||||
|
processRunner.WorkingDirectory = processStartInfo.WorkingDirectory; |
||||||
|
processRunner.Start(processStartInfo.FileName, processStartInfo.Arguments); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Stop() |
||||||
|
{ |
||||||
|
processRunner.Kill(); |
||||||
|
testResultsMonitor.Stop(); |
||||||
|
testResultsMonitor.Read(); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Dispose() |
||||||
|
{ |
||||||
|
testResultsMonitor.Dispose(); |
||||||
|
testResultsMonitor.TestFinished -= OnTestFinished; |
||||||
|
processRunner.ErrorLineReceived -= OutputLineReceived; |
||||||
|
processRunner.OutputLineReceived -= OutputLineReceived; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,102 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class TestResultTask |
||||||
|
{ |
||||||
|
TestResultTask() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public static Task Create(TestResult result, TestProject project) |
||||||
|
{ |
||||||
|
TaskType taskType = TaskType.Warning; |
||||||
|
FileLineReference lineRef = null; |
||||||
|
string message = String.Empty; |
||||||
|
|
||||||
|
if (result.IsFailure) { |
||||||
|
taskType = TaskType.Error; |
||||||
|
if (!result.StackTraceFilePosition.IsEmpty) { |
||||||
|
lineRef = new FileLineReference(result.StackTraceFilePosition.FileName, result.StackTraceFilePosition.Line - 1, result.StackTraceFilePosition.Column - 1); |
||||||
|
} |
||||||
|
message = GetTestFailedMessage(result); |
||||||
|
} else if (result.IsIgnored) { |
||||||
|
message = GetTestIgnoredMessage(result); |
||||||
|
} |
||||||
|
if (lineRef == null) { |
||||||
|
lineRef = FindTest(result.Name, project); |
||||||
|
} |
||||||
|
FileName fileName = null; |
||||||
|
if (lineRef != null) { |
||||||
|
fileName = new FileName(Path.GetFullPath(lineRef.FileName)); |
||||||
|
int line = lineRef.Line + 1; |
||||||
|
return new Task(fileName, message, lineRef.Column, line, taskType); |
||||||
|
} |
||||||
|
return new Task(fileName, message, 0, 0, taskType); |
||||||
|
} |
||||||
|
|
||||||
|
static string GetTestFailedMessage(TestResult result) |
||||||
|
{ |
||||||
|
string resource = "${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}"; |
||||||
|
return GetTestResultMessage(result, resource); |
||||||
|
} |
||||||
|
|
||||||
|
static string GetTestIgnoredMessage(TestResult result) |
||||||
|
{ |
||||||
|
string resource = "${res:NUnitPad.NUnitPadContent.TestTreeView.TestNotExecutedMessage}"; |
||||||
|
return GetTestResultMessage(result, resource); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the test result message if there is on otherwise
|
||||||
|
/// uses the string resource to create a message.
|
||||||
|
/// </summary>
|
||||||
|
static string GetTestResultMessage(TestResult result, string stringResource) |
||||||
|
{ |
||||||
|
if (result.Message.Length > 0) { |
||||||
|
return result.Message; |
||||||
|
} |
||||||
|
return GetTestResultMessageFromResource(result, stringResource); |
||||||
|
} |
||||||
|
|
||||||
|
static string GetTestResultMessageFromResource(TestResult result, string stringResource) |
||||||
|
{ |
||||||
|
string [,] customTags = new string[,] {{"TestCase", result.Name}}; |
||||||
|
return StringParser.Parse(stringResource, customTags); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the location of the specified test method in the
|
||||||
|
/// project being tested.
|
||||||
|
/// </summary>
|
||||||
|
static FileLineReference FindTest(string methodName, TestProject testProject) |
||||||
|
{ |
||||||
|
if (testProject != null) { |
||||||
|
TestMethod testMethod = testProject.TestClasses.GetTestMethod(methodName); |
||||||
|
if (testMethod != null) { |
||||||
|
return FindTest(testMethod); |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
static FileLineReference FindTest(TestMethod testMethod) |
||||||
|
{ |
||||||
|
MemberResolveResult resolveResult = new MemberResolveResult(null, null, testMethod.Method); |
||||||
|
FilePosition filePos = resolveResult.GetDefinitionPosition(); |
||||||
|
return new FileLineReference(filePos.FileName, filePos.Line - 1, filePos.Column - 1); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,72 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public abstract class TestRunnerBase : ITestRunner |
||||||
|
{ |
||||||
|
public TestRunnerBase() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) |
||||||
|
{ |
||||||
|
return new ProcessStartInfo(); |
||||||
|
} |
||||||
|
|
||||||
|
protected void LogCommandLine(ProcessStartInfo startInfo) |
||||||
|
{ |
||||||
|
string commandLine = GetCommandLine(startInfo); |
||||||
|
OnMessageReceived(commandLine); |
||||||
|
} |
||||||
|
|
||||||
|
protected string GetCommandLine(ProcessStartInfo startInfo) |
||||||
|
{ |
||||||
|
return String.Format("\"{0}\" {1}", startInfo.FileName, startInfo.Arguments); |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler AllTestsFinished; |
||||||
|
|
||||||
|
protected void OnAllTestsFinished(object source, EventArgs e) |
||||||
|
{ |
||||||
|
if (AllTestsFinished != null) { |
||||||
|
AllTestsFinished(source, e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public event TestFinishedEventHandler TestFinished; |
||||||
|
|
||||||
|
protected void OnTestFinished(object source, TestFinishedEventArgs e) |
||||||
|
{ |
||||||
|
if (TestFinished != null) { |
||||||
|
TestResult testResult = CreateTestResultForTestFramework(e.Result); |
||||||
|
TestFinished(source, new TestFinishedEventArgs(testResult)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual TestResult CreateTestResultForTestFramework(TestResult testResult) |
||||||
|
{ |
||||||
|
return testResult; |
||||||
|
} |
||||||
|
|
||||||
|
public event MessageReceivedEventHandler MessageReceived; |
||||||
|
|
||||||
|
protected virtual void OnMessageReceived(string message) |
||||||
|
{ |
||||||
|
if (MessageReceived != null) { |
||||||
|
MessageReceived(this, new MessageReceivedEventArgs(message)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public abstract void Dispose(); |
||||||
|
public abstract void Stop(); |
||||||
|
public abstract void Start(SelectedTests selectedTests); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public static class TestService |
||||||
|
{ |
||||||
|
static IRegisteredTestFrameworks testFrameworks; |
||||||
|
static MessageViewCategory unitTestMessageView; |
||||||
|
|
||||||
|
public static IRegisteredTestFrameworks RegisteredTestFrameworks { |
||||||
|
get { |
||||||
|
CreateRegisteredTestFrameworks(); |
||||||
|
return testFrameworks; |
||||||
|
} |
||||||
|
set { testFrameworks = value; } |
||||||
|
} |
||||||
|
|
||||||
|
static void CreateRegisteredTestFrameworks() |
||||||
|
{ |
||||||
|
if (testFrameworks == null) { |
||||||
|
UnitTestAddInTree addInTree = new UnitTestAddInTree(); |
||||||
|
testFrameworks = new RegisteredTestFrameworks(addInTree); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static MessageViewCategory UnitTestMessageView { |
||||||
|
get { |
||||||
|
if (unitTestMessageView == null) { |
||||||
|
CreateUnitTestCategory(); |
||||||
|
} |
||||||
|
return unitTestMessageView; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void CreateUnitTestCategory() |
||||||
|
{ |
||||||
|
MessageViewCategory.Create(ref unitTestMessageView, |
||||||
|
"UnitTesting", |
||||||
|
"${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestAddInTree : IAddInTree |
||||||
|
{ |
||||||
|
public List<T> BuildItems<T>(string path, object caller) |
||||||
|
{ |
||||||
|
return AddInTree.BuildItems<T>(path, caller); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestBuildOptions : IBuildOptions |
||||||
|
{ |
||||||
|
public bool ShowErrorListAfterBuild { |
||||||
|
get { return BuildOptions.ShowErrorListAfterBuild; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestBuildProjectFactory : IBuildProjectFactory |
||||||
|
{ |
||||||
|
public BuildProjectBeforeTestRun CreateBuildProjectBeforeTestRun(IProject project) |
||||||
|
{ |
||||||
|
return new BuildProjectBeforeTestRun(project); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Debugging; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestDebuggerService : IUnitTestDebuggerService |
||||||
|
{ |
||||||
|
public bool IsDebuggerLoaded { |
||||||
|
get { return DebuggerService.IsDebuggerLoaded; } |
||||||
|
} |
||||||
|
|
||||||
|
public IDebugger CurrentDebugger { |
||||||
|
get { return DebuggerService.CurrentDebugger; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestFileService : IUnitTestFileService |
||||||
|
{ |
||||||
|
public void OpenFile(string fileName) |
||||||
|
{ |
||||||
|
FileService.OpenFile(fileName); |
||||||
|
} |
||||||
|
|
||||||
|
public void JumpToFilePosition(string fileName, int line, int column) |
||||||
|
{ |
||||||
|
FileService.JumpToFilePosition(fileName, line, column); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestMessageService : IUnitTestMessageService |
||||||
|
{ |
||||||
|
public bool AskQuestion(string question, string caption) |
||||||
|
{ |
||||||
|
return MessageService.AskQuestion(question, caption); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Util; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestProcessRunner : IUnitTestProcessRunner |
||||||
|
{ |
||||||
|
ProcessRunner runner; |
||||||
|
|
||||||
|
public event LineReceivedEventHandler OutputLineReceived { |
||||||
|
add { runner.OutputLineReceived += value; } |
||||||
|
remove { runner.OutputLineReceived -= value; } |
||||||
|
} |
||||||
|
|
||||||
|
public event LineReceivedEventHandler ErrorLineReceived { |
||||||
|
add { runner.ErrorLineReceived += value; } |
||||||
|
remove { runner.ErrorLineReceived -= value; } |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler ProcessExited { |
||||||
|
add { runner.ProcessExited += value; } |
||||||
|
remove { runner.ProcessExited -= value; } |
||||||
|
} |
||||||
|
|
||||||
|
public UnitTestProcessRunner() |
||||||
|
{ |
||||||
|
runner = new ProcessRunner(); |
||||||
|
} |
||||||
|
|
||||||
|
public bool LogStandardOutputAndError { |
||||||
|
get { return runner.LogStandardOutputAndError; } |
||||||
|
set { runner.LogStandardOutputAndError = value; } |
||||||
|
} |
||||||
|
|
||||||
|
public string WorkingDirectory { |
||||||
|
get { return runner.WorkingDirectory; } |
||||||
|
set { runner.WorkingDirectory = value; } |
||||||
|
} |
||||||
|
|
||||||
|
public void Start(string command, string arguments) |
||||||
|
{ |
||||||
|
runner.Start(command, arguments); |
||||||
|
} |
||||||
|
|
||||||
|
public void Kill() |
||||||
|
{ |
||||||
|
runner.Kill(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestSaveAllFilesCommand : IUnitTestSaveAllFilesCommand |
||||||
|
{ |
||||||
|
public void SaveAllFiles() |
||||||
|
{ |
||||||
|
ICSharpCode.SharpDevelop.Commands.SaveAllFiles.SaveAll(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestTaskService : IUnitTestTaskService |
||||||
|
{ |
||||||
|
public void ClearExceptCommentTasks() |
||||||
|
{ |
||||||
|
TaskService.ClearExceptCommentTasks(); |
||||||
|
} |
||||||
|
|
||||||
|
public bool InUpdate { |
||||||
|
get { return TaskService.InUpdate; } |
||||||
|
set { TaskService.InUpdate = value; } |
||||||
|
} |
||||||
|
|
||||||
|
public MessageViewCategory BuildMessageViewCategory { |
||||||
|
get { return TaskService.BuildMessageViewCategory; } |
||||||
|
} |
||||||
|
|
||||||
|
public void Add(Task task) |
||||||
|
{ |
||||||
|
TaskService.Add(task); |
||||||
|
} |
||||||
|
|
||||||
|
public bool SomethingWentWrong { |
||||||
|
get { return TaskService.SomethingWentWrong; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.UnitTesting |
||||||
|
{ |
||||||
|
public class UnitTestWorkbench : IUnitTestWorkbench |
||||||
|
{ |
||||||
|
public PadDescriptor GetPad(Type type) |
||||||
|
{ |
||||||
|
return WorkbenchSingleton.Workbench.GetPad(type); |
||||||
|
} |
||||||
|
|
||||||
|
public void SafeThreadAsyncCall(Action method) |
||||||
|
{ |
||||||
|
WorkbenchSingleton.SafeThreadAsyncCall(method); |
||||||
|
} |
||||||
|
|
||||||
|
public void SafeThreadAsyncCall<A>(Action<A> method, A arg1) |
||||||
|
{ |
||||||
|
WorkbenchSingleton.SafeThreadAsyncCall(method, arg1); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class CreateNUnitTestRunnerTestFixture |
||||||
|
{ |
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
if (!PropertyService.Initialized) { |
||||||
|
PropertyService.InitializeService(String.Empty, String.Empty, String.Empty); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NUnitTestFrameworkCreateTestRunnerReturnsNUnitTestRunner() |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework = new NUnitTestFramework(); |
||||||
|
Assert.IsInstanceOf(typeof(NUnitTestRunner), testFramework.CreateTestRunner()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NUnitTestFrameworkCreateTestDebuggerReturnsNUnitTestDebugger() |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework = new NUnitTestFramework(); |
||||||
|
Assert.IsInstanceOf(typeof(NUnitTestDebugger), testFramework.CreateTestDebugger()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsBuildNeededBeforeTestRunReturnsTrue() |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework = new NUnitTestFramework(); |
||||||
|
Assert.IsTrue(testFramework.IsBuildNeededBeforeTestRun); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,266 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitConsoleCommandLineTests |
||||||
|
{ |
||||||
|
CompilableProject project; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void SetUp() |
||||||
|
{ |
||||||
|
project = new MockCSharpProject(); |
||||||
|
project.FileName = @"C:\Projects\MyTests\MyTests.csproj"; |
||||||
|
project.AssemblyName = "MyTests"; |
||||||
|
project.OutputType = OutputType.Library; |
||||||
|
project.SetProperty("OutputPath", null); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestResultsFile() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.Results = @"C:\results.txt"; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /results=\"C:\\results.txt\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoLogo() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = true; |
||||||
|
app.ShadowCopy = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nologo"; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoShadowCopy() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = false; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /noshadow"; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoThread() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.NoThread = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nothread"; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoDots() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.NoDots = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nodots"; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Labels() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.Labels = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /labels"; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFixture() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.Fixture = "TestFixture"; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestNamespace() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.NamespaceFilter = "TestFixture"; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void XmlOutputFile() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.XmlOutputFile = @"C:\NUnit.xml"; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /xml=\"C:\\NUnit.xml\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestMethod() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.Fixture = "TestFixture"; |
||||||
|
app.Test = "Test"; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture.Test\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestMethodSpecifiedInInitialize() |
||||||
|
{ |
||||||
|
MockClass testFixture = new MockClass("TestFixture"); |
||||||
|
MockMethod testMethod = new MockMethod(testFixture, "Test"); |
||||||
|
SelectedTests selectedTests = new SelectedTests(project, null, testFixture, testMethod); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture.Test\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestNamespaceSpecifiedInInitialize() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project, "Project.MyTests", null, null); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"Project.MyTests\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FullCommandLine() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = true; |
||||||
|
app.ShadowCopy = true; |
||||||
|
|
||||||
|
FileUtility.ApplicationRootPath = @"C:\SharpDevelop"; |
||||||
|
|
||||||
|
string expectedFullCommandLine = |
||||||
|
"\"C:\\SharpDevelop\\bin\\Tools\\NUnit\\nunit-console-x86.exe\" " + |
||||||
|
"\"C:\\Projects\\MyTests\\MyTests.dll\" " + |
||||||
|
"/nologo"; |
||||||
|
Assert.AreEqual(expectedFullCommandLine, app.GetCommandLine()); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that a space is appended between the items added
|
||||||
|
/// to the UnitTestApplicationStartapp.Assemblies
|
||||||
|
/// when the command line is generated.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void SecondAssemblySpecified() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.Assemblies.Add("SecondAssembly.dll"); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
app.Results = @"C:\results.txt"; |
||||||
|
|
||||||
|
string expectedCommandLine = |
||||||
|
"\"C:\\Projects\\MyTests\\MyTests.dll\" " + |
||||||
|
"\"SecondAssembly.dll\" " + |
||||||
|
"/results=\"C:\\results.txt\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProject() |
||||||
|
{ |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
Assert.AreSame(project, app.Project); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestInnerClassSpecifiedInInitialize() |
||||||
|
{ |
||||||
|
MockClass testFixture = new MockClass("MyTests.TestFixture.InnerTest", "MyTests.TestFixture+InnerTest"); |
||||||
|
SelectedTests selectedTests = new SelectedTests(project, null, testFixture, null); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
|
||||||
|
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" " + |
||||||
|
"/run=\"MyTests.TestFixture+InnerTest\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void XmlOutputFileNameSpecifiedOnCommandLine() |
||||||
|
{ |
||||||
|
UnitTestingOptions options = new UnitTestingOptions(new Properties()); |
||||||
|
options.CreateXmlOutputFile = true; |
||||||
|
MockClass testFixture = new MockClass("MyTests.TestFixture.MyTest"); |
||||||
|
SelectedTests selectedTests = new SelectedTests(project, null, testFixture, null); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options); |
||||||
|
app.NoLogo = false; |
||||||
|
app.ShadowCopy = true; |
||||||
|
|
||||||
|
string expectedCommandLine = |
||||||
|
"\"C:\\Projects\\MyTests\\MyTests.dll\" " + |
||||||
|
"/xml=\"C:\\Projects\\MyTests\\MyTests-TestResult.xml\" " + |
||||||
|
"/run=\"MyTests.TestFixture.MyTest\""; |
||||||
|
Assert.AreEqual(expectedCommandLine, app.GetArguments()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitConsoleProcessStartInfoTestFixture |
||||||
|
{ |
||||||
|
ProcessStartInfo info; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
FileUtility.ApplicationRootPath = @"C:\SharpDevelop"; |
||||||
|
} |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
SelectedTests selectedTests = new SelectedTests(project); |
||||||
|
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests); |
||||||
|
|
||||||
|
info = app.GetProcessStartInfo(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void WorkingDirectoryIsNUnitConsoleApplicationDirectory() |
||||||
|
{ |
||||||
|
string expectedDirectory = @"C:\SharpDevelop\bin\Tools\NUnit"; |
||||||
|
Assert.AreEqual(expectedDirectory, info.WorkingDirectory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FileNameIsNUnitConsoleExe() |
||||||
|
{ |
||||||
|
string expectedFileName = @"C:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe"; |
||||||
|
Assert.AreEqual(expectedFileName, info.FileName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CommandLineArgumentsAreNUnitConsoleExeCommandLineArguments() |
||||||
|
{ |
||||||
|
string expectedCommandLine = |
||||||
|
"\"c:\\projects\\MyTests\\bin\\Debug\\MyTests.dll\""; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCommandLine, info.Arguments); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitTestFrameworkIsTestClassTests |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
testFramework = new NUnitTestFramework(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsFalseHasClassHasNoAttributes() |
||||||
|
{ |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
Assert.IsFalse(testFramework.IsTestClass(mockClass)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsTrueHasClassHasTestFixtureAttributeMissingAttributePart() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("TestFixture"); |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithAttribute(testAttribute); |
||||||
|
Assert.IsTrue(testFramework.IsTestClass(mockClass)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsTrueHasClassHasTestFixtureAttribute() |
||||||
|
{ |
||||||
|
MockAttribute testFixtureAttribute = new MockAttribute("TestFixtureAttribute"); |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithAttribute(testFixtureAttribute); |
||||||
|
Assert.IsTrue(testFramework.IsTestClass(mockClass)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsTrueHasClassHasFullyQualifiedNUnitTestFixtureAttribute() |
||||||
|
{ |
||||||
|
MockAttribute testFixtureAttribute = new MockAttribute("NUnit.Framework.TestFixtureAttribute"); |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithAttribute(testFixtureAttribute); |
||||||
|
Assert.IsTrue(testFramework.IsTestClass(mockClass)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsFalseWhenClassIsNull() |
||||||
|
{ |
||||||
|
Assert.IsFalse(testFramework.IsTestClass(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsFalseWhenProjectContentLanguageIsNull() |
||||||
|
{ |
||||||
|
IProject project = new MockCSharpProject(); |
||||||
|
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||||
|
mockProjectContent.Project = project; |
||||||
|
MockClass mockClass = new MockClass(mockProjectContent); |
||||||
|
|
||||||
|
Assert.IsFalse(testFramework.IsTestClass(mockClass)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsFalseWhenProjectContentLanguageNameComparerIsNull() |
||||||
|
{ |
||||||
|
IProject project = new MockCSharpProject(); |
||||||
|
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||||
|
mockProjectContent.Project = project; |
||||||
|
mockProjectContent.Language = new LanguageProperties(null); |
||||||
|
MockClass mockClass = new MockClass(mockProjectContent); |
||||||
|
mockClass.Attributes.Add(new MockAttribute("Test")); |
||||||
|
|
||||||
|
Assert.IsFalse(testFramework.IsTestClass(mockClass)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,113 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitTestFrameworkIsTestMethodTests |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
testFramework = new NUnitTestFramework(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsFalseWhenMethodHasNoAttributes() |
||||||
|
{ |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
Assert.IsFalse(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeWithoutAttributePart() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("Test"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
Assert.IsTrue(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeAttribute() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("TestAttribute"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
Assert.IsTrue(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsTrueWhenMethodHasFullyQualifiedNUnitTestAttribute() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("NUnit.Framework.TestAttribute"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
Assert.IsTrue(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsFalseWhenMethodIsNull() |
||||||
|
{ |
||||||
|
Assert.IsFalse(testFramework.IsTestMethod(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsFalseWhenProjectContentLanguageHasNullNameComparer() |
||||||
|
{ |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
mockClass.MockProjectContent.Language = new LanguageProperties(null); |
||||||
|
MockMethod mockMethod = new MockMethod(mockClass); |
||||||
|
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||||
|
|
||||||
|
Assert.IsFalse(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Even if the project is null the method should be
|
||||||
|
/// flagged as a TestMethod.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsTrueWhenProjectIsNull() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("Test"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent; |
||||||
|
mockProjectContent.Project = null; |
||||||
|
|
||||||
|
Assert.IsTrue(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsFalseWhenMethodHasNullLanguage() |
||||||
|
{ |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
mockClass.MockProjectContent.Language = null; |
||||||
|
MockMethod mockMethod = new MockMethod(mockClass); |
||||||
|
|
||||||
|
Assert.IsFalse(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsFalseWhenMethodHasHasParameters() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("Test"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
MockParameter mockParameter = new MockParameter(); |
||||||
|
mockMethod.Parameters.Add(mockParameter); |
||||||
|
|
||||||
|
Assert.IsFalse(testFramework.IsTestMethod(mockMethod)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitTestFrameworkIsTestProjectTests |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
testFramework = new NUnitTestFramework(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NUnitTestFrameworkImplementsITestFramework() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(testFramework as ITestFramework); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsFalseForNullProject() |
||||||
|
{ |
||||||
|
Assert.IsFalse(testFramework.IsTestProject(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReference() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
|
||||||
|
ReferenceProjectItem systemRef = new ReferenceProjectItem(project, "System"); |
||||||
|
ProjectService.AddProjectItem(project, systemRef); |
||||||
|
|
||||||
|
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, "NUnit.Framework"); |
||||||
|
ProjectService.AddProjectItem(project, nunitFrameworkRef); |
||||||
|
|
||||||
|
Assert.IsTrue(testFramework.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsFalseForProjectWithoutNUnitFrameworkAssemblyReference() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
Assert.IsFalse(testFramework.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReferenceIgnoringCase() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
|
||||||
|
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, "NUNIT.FRAMEWORK"); |
||||||
|
ProjectService.AddProjectItem(project, nunitFrameworkRef); |
||||||
|
|
||||||
|
Assert.IsTrue(testFramework.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReferenceIgnoringNonReferenceProjectItems() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
|
||||||
|
FileProjectItem fileItem = new FileProjectItem(project, ItemType.Compile, "test.cs"); |
||||||
|
ProjectService.AddProjectItem(project, fileItem); |
||||||
|
|
||||||
|
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, "nunit.framework"); |
||||||
|
ProjectService.AddProjectItem(project, nunitFrameworkRef); |
||||||
|
|
||||||
|
Assert.IsTrue(testFramework.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReferenceUsingFullName() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
string assemblyName = "nunit.framework, Version=2.5.3.9345, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"; |
||||||
|
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, assemblyName); |
||||||
|
ProjectService.AddProjectItem(project, nunitFrameworkRef); |
||||||
|
|
||||||
|
Assert.IsTrue(testFramework.IsTestProject(project)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Tree |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitTestResultFailureTestFixture |
||||||
|
{ |
||||||
|
NUnitTestResult nunitTestResult; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
TestResult testResult = new TestResult("MyNamespace.MyTests"); |
||||||
|
testResult.ResultType = TestResultType.Failure; |
||||||
|
testResult.Message = "Test failed"; |
||||||
|
testResult.StackTrace = |
||||||
|
"Test Error : MyTest.Test\r\n" + |
||||||
|
"at TestResultTask.Create() in c:\\projects\\SharpDevelop\\TestResultTask.cs:line 45\r\n" + |
||||||
|
"at MyTest.Test() in c:\\myprojects\\test\\..\\test\\mytest.cs:line 28\r\n" + |
||||||
|
""; |
||||||
|
nunitTestResult = new NUnitTestResult(testResult); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestResultTypeIsFailure() |
||||||
|
{ |
||||||
|
Assert.AreEqual(TestResultType.Failure, nunitTestResult.ResultType); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestResultMessageIsTestFailed() |
||||||
|
{ |
||||||
|
Assert.AreEqual("Test failed", nunitTestResult.Message); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void StackTraceFilePositionFileNameMatchesLastFileNameInStackTrace() |
||||||
|
{ |
||||||
|
string expectedFileName = @"c:\myprojects\test\mytest.cs"; |
||||||
|
Assert.AreEqual(expectedFileName, nunitTestResult.StackTraceFilePosition.FileName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void StackTraceFilePositionLineNumberIs28WhichIsEqualToReportedNUnitErrorLine() |
||||||
|
{ |
||||||
|
Assert.AreEqual(28, nunitTestResult.StackTraceFilePosition.Line); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void StackTraceFilePositionColumnNumberIsOne() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, nunitTestResult.StackTraceFilePosition.Column); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ChangingStackTraceToEmptyStringSetsStackTraceFilePositionToEmpty() |
||||||
|
{ |
||||||
|
nunitTestResult.StackTraceFilePosition = new FilePosition("test.cs", 10, 2); |
||||||
|
nunitTestResult.StackTrace = String.Empty; |
||||||
|
Assert.IsTrue(nunitTestResult.StackTraceFilePosition.IsEmpty); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,240 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RegisteredTestFrameworksTestFixture |
||||||
|
{ |
||||||
|
RegisteredTestFrameworks testFrameworks; |
||||||
|
MockTestFramework nunitTestFramework; |
||||||
|
MockTestFramework mbUnitTestFramework; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
List<TestFrameworkDescriptor> descriptors = new List<TestFrameworkDescriptor>(); |
||||||
|
|
||||||
|
MockTestFrameworkFactory factory = new MockTestFrameworkFactory(); |
||||||
|
|
||||||
|
Properties mbUnitProperties = new Properties(); |
||||||
|
mbUnitProperties["id"] = "mbunit"; |
||||||
|
mbUnitProperties["class"] = "MBUnitTestFramework"; |
||||||
|
mbUnitProperties["supportedProjects"] = ".vbproj"; |
||||||
|
mbUnitTestFramework = new MockTestFramework(); |
||||||
|
factory.Add("MBUnitTestFramework", mbUnitTestFramework); |
||||||
|
|
||||||
|
Properties nunitProperties = new Properties(); |
||||||
|
nunitProperties["id"] = "nunit"; |
||||||
|
nunitProperties["class"] = "NUnitTestFramework"; |
||||||
|
nunitProperties["supportedProjects"] = ".csproj"; |
||||||
|
nunitTestFramework = new MockTestFramework(); |
||||||
|
factory.Add("NUnitTestFramework", nunitTestFramework); |
||||||
|
|
||||||
|
TestFrameworkDescriptor mbUnitDescriptor = new TestFrameworkDescriptor(mbUnitProperties, factory); |
||||||
|
TestFrameworkDescriptor nunitDescriptor = new TestFrameworkDescriptor(nunitProperties, factory); |
||||||
|
|
||||||
|
descriptors.Add(mbUnitDescriptor); |
||||||
|
descriptors.Add(nunitDescriptor); |
||||||
|
|
||||||
|
MockAddInTree addinTree = new MockAddInTree(); |
||||||
|
addinTree.AddItems("/SharpDevelop/UnitTesting/TestFrameworks", descriptors); |
||||||
|
|
||||||
|
testFrameworks = new RegisteredTestFrameworks(addinTree); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NUnitTestFrameworkRegisteredForUseWithProjectsWithCSharpProjectFileExtension() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test\MyProj.csproj"; |
||||||
|
|
||||||
|
Assert.AreEqual(nunitTestFramework, testFrameworks.GetTestFrameworkForProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MbUnitTestFrameworkRegisteredForUseWithProjectsWithVBNetProjectFileExtension() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test\MyProj.vbproj"; |
||||||
|
|
||||||
|
Assert.AreEqual(mbUnitTestFramework, testFrameworks.GetTestFrameworkForProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsFalseForUnknownMbUnitFrameworkTestMethod() |
||||||
|
{ |
||||||
|
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
method.MockDeclaringType.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj"; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsTestMethod(method)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodReturnsTrueForKnownMbUnitFrameworkTestMethod() |
||||||
|
{ |
||||||
|
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
method.MockDeclaringType.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj"; |
||||||
|
|
||||||
|
mbUnitTestFramework.AddTestMethod(method); |
||||||
|
|
||||||
|
Assert.IsTrue(testFrameworks.IsTestMethod(method)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodDoesNotThrowNullReferenceExceptionWhenNoTestFrameworkSupportsProject() |
||||||
|
{ |
||||||
|
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
method.MockDeclaringType.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.unknown"; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsTestMethod(method)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMethodDoesNotThrowNullReferenceWhenNullPassedToMethod() |
||||||
|
{ |
||||||
|
Assert.IsFalse(testFrameworks.IsTestMethod(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsFalseForUnknownMbUnitFrameworkTestClass() |
||||||
|
{ |
||||||
|
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
c.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj"; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsTestClass(c)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassReturnsTrueForKnownMbUnitFrameworkTestClass() |
||||||
|
{ |
||||||
|
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
c.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj"; |
||||||
|
|
||||||
|
mbUnitTestFramework.AddTestClass(c); |
||||||
|
|
||||||
|
Assert.IsTrue(testFrameworks.IsTestClass(c)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassDoesNotThrowNullReferenceExceptionWhenNoTestFrameworkSupportsProject() |
||||||
|
{ |
||||||
|
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
c.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.unknown"; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsTestClass(c)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestClassDoesNotThrowNullReferenceWhenNullPassedToMethod() |
||||||
|
{ |
||||||
|
Assert.IsFalse(testFrameworks.IsTestClass(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsFalseForUnknownMbUnitFrameworkTestProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.vbproj"; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectReturnsTrueForKnownMbUnitFrameworkTestProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.vbproj"; |
||||||
|
|
||||||
|
mbUnitTestFramework.AddTestProject(project); |
||||||
|
|
||||||
|
Assert.IsTrue(testFrameworks.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectDoesNotThrowNullReferenceExceptionWhenNoTestFrameworkSupportsProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.unknown"; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsTestProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestProjectDoesNotThrowNullReferenceWhenNullPassedToMethod() |
||||||
|
{ |
||||||
|
Assert.IsFalse(testFrameworks.IsTestProject(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateTestRunnerReturnsNewTestRunnerFromCorrectTestFramework() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.csproj"; |
||||||
|
|
||||||
|
ITestRunner testRunner = testFrameworks.CreateTestRunner(project); |
||||||
|
ITestRunner[] expectedTestRunners = new ITestRunner[] { testRunner }; |
||||||
|
Assert.AreEqual(expectedTestRunners, nunitTestFramework.TestRunnersCreated.ToArray()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateTestRunnerDoesNotThrowNullRefExceptionWhenUnknownProjectPassedToCreateTestRunnerMethod() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.unknown"; |
||||||
|
|
||||||
|
Assert.IsNull(testFrameworks.CreateTestRunner(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateTestDebuggerReturnsNewTestRunnerFromCorrectTestFramework() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.csproj"; |
||||||
|
|
||||||
|
ITestRunner testDebugger = testFrameworks.CreateTestDebugger(project); |
||||||
|
ITestRunner[] expectedTestRunners = new ITestRunner[] { testDebugger }; |
||||||
|
Assert.AreEqual(expectedTestRunners, nunitTestFramework.TestDebuggersCreated.ToArray()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CreateTestDebuggerDoesNotThrowNullRefExceptionWhenUnknownProjectPassedToCreateTestRunnerMethod() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.unknown"; |
||||||
|
|
||||||
|
Assert.IsNull(testFrameworks.CreateTestDebugger(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsBuildNeededBeforeTestRunReturnsTrueWhenTestFrameworkIsBuildNeededBeforeTestRunSetToTrue() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.csproj"; |
||||||
|
nunitTestFramework.IsBuildNeededBeforeTestRun = true; |
||||||
|
|
||||||
|
Assert.IsTrue(testFrameworks.IsBuildNeededBeforeTestRunForProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsBuildNeededBeforeTestRunReturnsFalseWhenTestFrameworkIsBuildNeededBeforeTestRunSetToFalse() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\test.csproj"; |
||||||
|
nunitTestFramework.IsBuildNeededBeforeTestRun = false; |
||||||
|
|
||||||
|
Assert.IsFalse(testFrameworks.IsBuildNeededBeforeTestRunForProject(project)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestFrameworkDescriptorIgnoresProjectFileExtensionWhitespaceTestFixture |
||||||
|
{ |
||||||
|
TestFrameworkDescriptor descriptor; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockTestFrameworkFactory factory = new MockTestFrameworkFactory(); |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties["id"] = "nunit"; |
||||||
|
properties["supportedProjects"] = " .csproj; .vbproj "; |
||||||
|
|
||||||
|
descriptor = new TestFrameworkDescriptor(properties, factory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForCSharpProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.csproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForVBNetProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.vbproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestFrameworkDescriptorSupportsCSharpAndVBNetProjectsTestFixture |
||||||
|
{ |
||||||
|
TestFrameworkDescriptor descriptor; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockTestFrameworkFactory factory = new MockTestFrameworkFactory(); |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties["id"] = "nunit"; |
||||||
|
properties["supportedProjects"] = ".csproj;.vbproj"; |
||||||
|
|
||||||
|
descriptor = new TestFrameworkDescriptor(properties, factory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForCSharpProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.csproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForVBNetProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.vbproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestFrameworkDescriptorSupportsCSharpProjectsTestFixture |
||||||
|
{ |
||||||
|
TestFrameworkDescriptor descriptor; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockTestFrameworkFactory factory = new MockTestFrameworkFactory(); |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties["id"] = "nunit"; |
||||||
|
properties["supportedProjects"] = ".csproj"; |
||||||
|
|
||||||
|
descriptor = new TestFrameworkDescriptor(properties, factory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForCSharpProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.csproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsFalseForVBNetProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.vbproj"; |
||||||
|
|
||||||
|
Assert.IsFalse(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsFalseForNullProject() |
||||||
|
{ |
||||||
|
Assert.IsFalse(descriptor.IsSupportedProject(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForCSharpProjectFileExtensionInUpperCase() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.CSPROJ"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestFrameworkDescriptorSupportsUpperCaseProjectFileExtensionsTestFixture |
||||||
|
{ |
||||||
|
TestFrameworkDescriptor descriptor; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockTestFrameworkFactory factory = new MockTestFrameworkFactory(); |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties["id"] = "nunit"; |
||||||
|
properties["supportedProjects"] = ".CSPROJ;.VBPROJ"; |
||||||
|
|
||||||
|
descriptor = new TestFrameworkDescriptor(properties, factory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForCSharpProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.csproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsSupportedProjectReturnsTrueForVBNetProject() |
||||||
|
{ |
||||||
|
MockCSharpProject project = new MockCSharpProject(); |
||||||
|
project.FileName = @"d:\projects\myproj.vbproj"; |
||||||
|
|
||||||
|
Assert.IsTrue(descriptor.IsSupportedProject(project)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestFrameworkDoozerTestFixture |
||||||
|
{ |
||||||
|
TestFrameworkDescriptor descriptor; |
||||||
|
TestFrameworkDoozer doozer; |
||||||
|
MockTestFramework mockTestFramework; |
||||||
|
MockTestFrameworkFactory mockTestFrameworkFactory; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties["id"] = "Default"; |
||||||
|
properties["class"] = "UnitTesting.Tests.Utils.MockTestFramework"; |
||||||
|
Codon codon = new Codon(null, "TestFramework", properties, null); |
||||||
|
|
||||||
|
mockTestFrameworkFactory = new MockTestFrameworkFactory(); |
||||||
|
mockTestFramework = new MockTestFramework(); |
||||||
|
mockTestFrameworkFactory.Add("UnitTesting.Tests.Utils.MockTestFramework", mockTestFramework); |
||||||
|
|
||||||
|
doozer = new TestFrameworkDoozer(); |
||||||
|
descriptor = doozer.BuildItem(codon, mockTestFrameworkFactory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFrameworkDescriptorIdIsDefault() |
||||||
|
{ |
||||||
|
Assert.AreEqual("Default", descriptor.Id); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFrameworkDoozerImplementsIDoozer() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(doozer as IDoozer); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFrameworkDoozerDoesNotHandleConditions() |
||||||
|
{ |
||||||
|
Assert.IsFalse(doozer.HandleConditions); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFrameworkDescriptorTestFrameworkPropertyReturnsMockTestFrameworkObject() |
||||||
|
{ |
||||||
|
Assert.IsTrue(descriptor.TestFramework is MockTestFramework); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFrameworkDescriptorTestFrameworkPropertyOnlyCreatesOneObject() |
||||||
|
{ |
||||||
|
ITestFramework testFramework = descriptor.TestFramework; |
||||||
|
testFramework = descriptor.TestFramework; |
||||||
|
|
||||||
|
List<string> expectedClassNames = new List<string>(); |
||||||
|
expectedClassNames.Add("UnitTesting.Tests.Utils.MockTestFramework"); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedClassNames, mockTestFrameworkFactory.ClassNamesPassedToCreateMethod); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Gui.ClassBrowser; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestableConditionIsValidForClassNodeTestFixture |
||||||
|
{ |
||||||
|
TestableCondition testableCondition; |
||||||
|
MockClass classWithTestAttribute; |
||||||
|
ClassNode classNodeForClassWithTestAttribute; |
||||||
|
MockRegisteredTestFrameworks testFrameworks; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
ResourceManager.Initialize(); |
||||||
|
} |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("Test"); |
||||||
|
classWithTestAttribute = MockClass.CreateMockClassWithAttribute(testAttribute); |
||||||
|
IProject project = classWithTestAttribute.MockProjectContent.ProjectAsIProject; |
||||||
|
classNodeForClassWithTestAttribute = new ClassNode(project, classWithTestAttribute); |
||||||
|
|
||||||
|
testFrameworks = new MockRegisteredTestFrameworks(); |
||||||
|
testFrameworks.AddTestClass(classWithTestAttribute); |
||||||
|
|
||||||
|
testableCondition = new TestableCondition(testFrameworks); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsValidReturnsTrueForClassWithTestAttribute() |
||||||
|
{ |
||||||
|
Assert.IsTrue(testableCondition.IsValid(classNodeForClassWithTestAttribute, null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsValidReturnsFalseForClassWithoutAnyAttributes() |
||||||
|
{ |
||||||
|
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
IProject project = c.MockProjectContent.ProjectAsIProject; |
||||||
|
ClassNode classNode = new ClassNode(project, c); |
||||||
|
Assert.IsFalse(testableCondition.IsValid(classNode, null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestClassPassedToRegisteredTestFrameworksIsTestClass() |
||||||
|
{ |
||||||
|
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
IProject project = c.MockProjectContent.ProjectAsIProject; |
||||||
|
ClassNode classNode = new ClassNode(project, c); |
||||||
|
testableCondition.IsValid(classNode, null); |
||||||
|
Assert.AreEqual(c, testFrameworks.IsTestClassParameterUsed); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When class.ProjectContent.Project == null the
|
||||||
|
/// TestableCondition.IsValid should return false.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void IsValidReturnFalseWhenProjectIsNull() |
||||||
|
{ |
||||||
|
classWithTestAttribute.MockProjectContent.Project = null; |
||||||
|
Assert.IsFalse(testableCondition.IsValid(classNodeForClassWithTestAttribute, null)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,67 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TestableConditionIsValidForMemberNodeTestFixture |
||||||
|
{ |
||||||
|
TestableCondition testableCondition; |
||||||
|
MockMethod methodWithTestAttribute; |
||||||
|
MockMemberNode memberNodeForMethodWithTestAttribute; |
||||||
|
MockRegisteredTestFrameworks testFrameworks; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
ResourceManager.Initialize(); |
||||||
|
} |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
MockAttribute testAttribute = new MockAttribute("Test"); |
||||||
|
methodWithTestAttribute = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
memberNodeForMethodWithTestAttribute = new MockMemberNode(methodWithTestAttribute); |
||||||
|
|
||||||
|
testFrameworks = new MockRegisteredTestFrameworks(); |
||||||
|
testFrameworks.AddTestMethod(methodWithTestAttribute); |
||||||
|
|
||||||
|
testableCondition = new TestableCondition(testFrameworks); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsValidReturnsTrueForMethodWithTestAttribute() |
||||||
|
{ |
||||||
|
Assert.IsTrue(testableCondition.IsValid(memberNodeForMethodWithTestAttribute, null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsValidReturnsFalseForMethodWithoutAnyAttributes() |
||||||
|
{ |
||||||
|
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
MockMemberNode memberNode = new MockMemberNode(method); |
||||||
|
Assert.IsFalse(testableCondition.IsValid(memberNode, null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestMethodPassedToRegisteredTestFrameworksIsTestMethod() |
||||||
|
{ |
||||||
|
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
MockMemberNode memberNode = new MockMemberNode(method); |
||||||
|
testableCondition.IsValid(memberNode, null); |
||||||
|
Assert.AreEqual(method, testFrameworks.IsTestMethodMemberParameterUsed); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue