Guest User

Untitled

a guest
Jan 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. [TestMethod]
  2. public void GetPath_Hardcoded()
  3. {
  4. MyClass target = new MyClass("fields", "that later", "determine", "a folder");
  5. string expected = "C:\Output Folder\fields\that later\determine\a folder";
  6. string actual = target.GetPath();
  7. Assert.AreEqual(expected, actual,
  8. "GetPath should return a full directory path based on its fields.");
  9. }
  10.  
  11. [TestMethod]
  12. public void GetPath_Softcoded()
  13. {
  14. MyClass target = new MyClass("fields", "that later", "determine", "a folder");
  15. string expected = "C:\Output Folder\" + string.Join("\", target.Field1, target.Field2, target.Field3, target.Field4);
  16. string actual = target.GetPath();
  17. Assert.AreEqual(expected, actual,
  18. "GetPath should return a full directory path based on its fields.");
  19. }
  20.  
  21. [TestMethod]
  22. public void GetPath_Option3()
  23. {
  24. string field1 = "fields";
  25. string field2 = "that later";
  26. string field3 = "determine";
  27. string field4 = "a folder";
  28. MyClass target = new MyClass(field1, field2, field3, field4);
  29. string expected = "C:\Output Folder\" + string.Join("\", field1, field2, field3, field4);
  30. string actual = target.GetPath();
  31. Assert.AreEqual(expected, actual,
  32. "GetPath should return a full directory path based on its fields.");
  33. }
  34.  
  35. MyTarget() // constructor
  36. {
  37. Field1 = Field2 = Field3 = Field4 = "";
  38. }
  39.  
  40. string expected = "C:\Output Folder" + string.Join("\", target.Field1, target.Field2, target.Field3, target.Field4);
  41.  
  42. [TestMethod]
  43. public void GetPath_Hardcoded()
  44. {
  45. const string f1 = "fields"; const string f2 = "that later";
  46. const string f3 = "determine; const string f4 = "a folder";
  47.  
  48. MyClass target = new MyClass( f1, f2, f3, f4 );
  49. string expected = "C:\Output Folder\" + string.Join("\", f1, f2, f3, f4);
  50. string actual = target.GetPath();
  51. Assert.AreEqual(expected, actual,
  52. "GetPath should return a full directory path based on its fields.");
  53. }
  54.  
  55. [TestMethod]
  56. public void GetPath_Tested(int CaseId)
  57. {
  58. testParams = GetTestConfig(caseID,"testConfig.txt"); // some wrapper that does read line and chops the field.
  59. MyClass target = new MyClass(testParams.field1, testParams.field2);
  60. string expected = testParams.field5;
  61. string actual = target.GetPath();
  62. Assert.AreEqual(expected, actual,
  63. "GetPath should return a full directory path based on its fields.");
  64. }
  65.  
  66. [TestMethod]
  67. public void GetPath_Softcoded()
  68. {
  69. //Hardcoded since you want to see what you expect is most simple and clear
  70. string expected = "C:\Output Folder\fields\that later\determine\a folder";
  71.  
  72. //If this test should also use a mocked filesystem it might be that you want to use
  73. //some base directory, which you could set in the setUp of your test class
  74. //that is usefull if you you need to run the same test on different environments
  75. string expected = this.outputPath + "fields\that later\determine\a folder";
  76.  
  77.  
  78. //another readable way could be interesting if you have difficult variables needed to test
  79. string fields = "fields";
  80. string thatLater = "that later";
  81. string determine = "determine";
  82. string aFolder = "a folder";
  83. string expected = this.outputPath + fields + "\" + thatLater + "\" + determine + "\" + aFolder;
  84. MyClass target = new MyClass(fields, thatLater, determine, aFolder);
  85.  
  86. //in general testing with real words is not needed, so code could be shorter on that
  87. //for testing difficult folder names you write a separate test anyway
  88. string f1 = "f1";
  89. string f2 = "f2";
  90. string f3 = "f3";
  91. string f4 = "f4";
  92. string expected = this.outputPath + f1 + "\" + f2 + "\" + f3 + "\" + f4;
  93. MyClass target = new MyClass(f1, f2, f3, f4);
  94.  
  95. //so here we start to see a structure, it looks more like an array of fields
  96. //so what would make testing more interesting with lots of variables is the use of a data provider
  97. //the data provider will re-use your test with many different kinds of inputs. That will reduce the amount of duplication of code for testing
  98. //http://msdn.microsoft.com/en-us/library/ms182527.aspx
  99.  
  100.  
  101. The part where you compare already seems correct
  102. MyClass target = new MyClass(fields, thatLater, determine, aFolder);
  103.  
  104. string actual = target.GetPath();
  105. Assert.AreEqual(expected, actual,
  106. "GetPath should return a full directory path based on its fields.");
  107. }
  108.  
  109. [TestCase("fields", "that later", "determine", "a folder", @"C:Output Folderfieldsthat laterdeterminea folder")]
  110. public void GetPathShouldReturnFullDirectoryPathBasedOnItsFields(
  111. string field1, string field2, string field3, string field,
  112. string expected)
  113. {
  114. MyClass target = new MyClass(field1, field2, field3, field4);
  115. string actual = target.GetPath();
  116. Assert.AreEqual(expected, actual,
  117. "GetPath should return a full directory path based on its fields.");
  118. }
Add Comment
Please, Sign In to add comment