Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestMethod]
- public void GetPath_Hardcoded()
- {
- MyClass target = new MyClass("fields", "that later", "determine", "a folder");
- string expected = "C:\Output Folder\fields\that later\determine\a folder";
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
- [TestMethod]
- public void GetPath_Softcoded()
- {
- MyClass target = new MyClass("fields", "that later", "determine", "a folder");
- string expected = "C:\Output Folder\" + string.Join("\", target.Field1, target.Field2, target.Field3, target.Field4);
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
- [TestMethod]
- public void GetPath_Option3()
- {
- string field1 = "fields";
- string field2 = "that later";
- string field3 = "determine";
- string field4 = "a folder";
- MyClass target = new MyClass(field1, field2, field3, field4);
- string expected = "C:\Output Folder\" + string.Join("\", field1, field2, field3, field4);
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
- MyTarget() // constructor
- {
- Field1 = Field2 = Field3 = Field4 = "";
- }
- string expected = "C:\Output Folder" + string.Join("\", target.Field1, target.Field2, target.Field3, target.Field4);
- [TestMethod]
- public void GetPath_Hardcoded()
- {
- const string f1 = "fields"; const string f2 = "that later";
- const string f3 = "determine; const string f4 = "a folder";
- MyClass target = new MyClass( f1, f2, f3, f4 );
- string expected = "C:\Output Folder\" + string.Join("\", f1, f2, f3, f4);
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
- [TestMethod]
- public void GetPath_Tested(int CaseId)
- {
- testParams = GetTestConfig(caseID,"testConfig.txt"); // some wrapper that does read line and chops the field.
- MyClass target = new MyClass(testParams.field1, testParams.field2);
- string expected = testParams.field5;
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
- [TestMethod]
- public void GetPath_Softcoded()
- {
- //Hardcoded since you want to see what you expect is most simple and clear
- string expected = "C:\Output Folder\fields\that later\determine\a folder";
- //If this test should also use a mocked filesystem it might be that you want to use
- //some base directory, which you could set in the setUp of your test class
- //that is usefull if you you need to run the same test on different environments
- string expected = this.outputPath + "fields\that later\determine\a folder";
- //another readable way could be interesting if you have difficult variables needed to test
- string fields = "fields";
- string thatLater = "that later";
- string determine = "determine";
- string aFolder = "a folder";
- string expected = this.outputPath + fields + "\" + thatLater + "\" + determine + "\" + aFolder;
- MyClass target = new MyClass(fields, thatLater, determine, aFolder);
- //in general testing with real words is not needed, so code could be shorter on that
- //for testing difficult folder names you write a separate test anyway
- string f1 = "f1";
- string f2 = "f2";
- string f3 = "f3";
- string f4 = "f4";
- string expected = this.outputPath + f1 + "\" + f2 + "\" + f3 + "\" + f4;
- MyClass target = new MyClass(f1, f2, f3, f4);
- //so here we start to see a structure, it looks more like an array of fields
- //so what would make testing more interesting with lots of variables is the use of a data provider
- //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
- //http://msdn.microsoft.com/en-us/library/ms182527.aspx
- The part where you compare already seems correct
- MyClass target = new MyClass(fields, thatLater, determine, aFolder);
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
- [TestCase("fields", "that later", "determine", "a folder", @"C:Output Folderfieldsthat laterdeterminea folder")]
- public void GetPathShouldReturnFullDirectoryPathBasedOnItsFields(
- string field1, string field2, string field3, string field,
- string expected)
- {
- MyClass target = new MyClass(field1, field2, field3, field4);
- string actual = target.GetPath();
- Assert.AreEqual(expected, actual,
- "GetPath should return a full directory path based on its fields.");
- }
Add Comment
Please, Sign In to add comment