PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/ParameterizedTestMethodSuite.cs

#
C# | 100 lines | 55 code | 11 blank | 34 comment | 8 complexity | 51a02d8cc7a1999f531ed64f70542b8d MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // Copyright 2008, Charlie Poole
  3. // This is free software licensed under the NUnit license. You may
  4. // obtain a copy of the license at http://nunit.org.
  5. // ****************************************************************
  6. using System.Reflection;
  7. using System.Text;
  8. namespace NUnit.Core
  9. {
  10. /// <summary>
  11. /// ParameterizedMethodSuite holds a collection of individual
  12. /// TestMethods with their arguments applied.
  13. /// </summary>
  14. public class ParameterizedMethodSuite : TestSuite
  15. {
  16. private bool isTheory;
  17. /// <summary>
  18. /// Construct from a MethodInfo
  19. /// </summary>
  20. /// <param name="method"></param>
  21. public ParameterizedMethodSuite(MethodInfo method)
  22. : base(method.ReflectedType.FullName, method.Name)
  23. {
  24. this.maintainTestOrder = true;
  25. this.isTheory = Reflect.HasAttribute(method, NUnitFramework.TheoryAttribute, true);
  26. }
  27. /// <summary>
  28. /// Gets a string representing the kind of test
  29. /// that this object represents, for use in display.
  30. /// </summary>
  31. public override string TestType
  32. {
  33. get
  34. {
  35. return this.isTheory
  36. ? "Theory"
  37. : "ParameterizedTest";
  38. }
  39. }
  40. /// <summary>
  41. /// Override Run, setting Fixture to that of the Parent.
  42. /// </summary>
  43. /// <param name="listener"></param>
  44. /// <param name="filter"></param>
  45. /// <returns></returns>
  46. public override TestResult Run(EventListener listener, ITestFilter filter)
  47. {
  48. if (this.Parent != null)
  49. {
  50. this.Fixture = this.Parent.Fixture;
  51. TestSuite suite = this.Parent as TestSuite;
  52. if (suite != null)
  53. {
  54. this.setUpMethods = suite.GetSetUpMethods();
  55. this.tearDownMethods = suite.GetTearDownMethods();
  56. }
  57. }
  58. // DYNAMIC: Get the parameters, and add the methods here.
  59. TestResult result = base.Run(listener, filter);
  60. if (this.isTheory && result.ResultState == ResultState.Inconclusive)
  61. result.SetResult(
  62. ResultState.Failure,
  63. this.TestCount == 0
  64. ? "No test cases were provided"
  65. : "All test cases were inconclusive",
  66. null);
  67. this.Fixture = null;
  68. this.setUpMethods = null;
  69. this.tearDownMethods = null;
  70. return result;
  71. }
  72. /// <summary>
  73. /// Override DoOneTimeSetUp to avoid executing any
  74. /// TestFixtureSetUp method for this suite
  75. /// </summary>
  76. /// <param name="suiteResult"></param>
  77. protected override void DoOneTimeSetUp(TestResult suiteResult)
  78. {
  79. }
  80. /// <summary>
  81. /// Override DoOneTimeTearDown to avoid executing any
  82. /// TestFixtureTearDown method for this suite.
  83. /// </summary>
  84. /// <param name="suiteResult"></param>
  85. protected override void DoOneTimeTearDown(TestResult suiteResult)
  86. {
  87. }
  88. }
  89. }