Challenges of refactoring unit-tests to be maintainable and readable when dealing with List<T> objects -
In the book, it talks about the desire to create a readable and readable unit test, mentioned in Approximate Page 204 It has been suggested that one should try to avoid several attempts in a test and perhaps the objects should be compared with the override aces method. When we have only one object to compare the expected vs. actual results, then it works great. However, if we have a list (or collection) of objects.
Consider the test given below. I have more than one emphasis In fact, two different ends are emphasized. In this case I will end up with 5 accused. 2 The contents of a list are present in the second, and 2 on the contrary. Compare the number of elements in the 5th list.
If anyone has suggestions for improving this test, then I am all ears. I am currently using MSTT, although I take the place for the fluent APIs with MNSTs of NUnets Lee
Current refinance code:
[TestMethod] #if! NUNIT [Host type ("mall")] # bell [molid] #endif Public Zero Load CSBbofometres_with Control CSVFile_Easy List OfxSvielFMterialsTatmitsInput () {// Object (s) Arrange var filepath = "File object does not cause mole paths is;"; String [] csvDataCorrectlyFormatted = {"1000, 1, Alt 1, TBD, 1, 10.0, Notes, Description, 2.50, A", "1001, 1, Alt 2 ,, TBD, 1, 10.0, Notes, 2.50, A,}}; Var Content Expected = New List & lt; CSVMaterial & gt; (); Content estimated. Add (New CSVMART ("1000", 1, "Alt 1", "TBD", 1m, 10.0m, "Notes", "Description", 2.50m, "A")); Content estimated. Add (New CSVMART ("1001", 1, "Alt 2", "TBD", 1m, 10.0m, "Notes", "Details", 2.50m, "A")); // Bye-Pass actually kills the file system and the CSV file MFile.ReadAllLinesString = s = & gt; Uses In-Memory Presentation. CsvDataCorrectlyFormatted; Work on objects (R) var contentActual = Mode CSIMport. Load CSBB Ophameters (FilePath); // Something discouraged is Assert.That (Material Actual Calculation, Is.EqualTo (Estimate estimated content); Content estimated.ForEach ((an estimated object) => responsibility (that is, the actual material included. (Original content) => responsibility; It contains content estimated (a relevant content));}
The original multi- Assert Unit-Test:
... // First Element Shelter Assign the contents (["] 1", content [0] .partNumber); assign it. Eraquall (1, content [0]. Secretarimanber); assurance. Array ("Alt 1", content [0] .ltPartNumber); Extraordinary. ("TBD", Content [0]. Vendor Code); Assurance (1m, content [0]. Quantity; Assur. (10.0m, content [0]. PARTWOIT); Assign. ("Notes", Content [0]. Partnotes); Compulsory ("Description", Content [0]. Part Description); Assurance. RE Wol (2.50 M, materials [0]. Unitkast); assurance. Early ( "A" material [1]. Modification); // to denote the second element. First ("1001", content [1]. Partnumber); Confirm. Erekwall (1, Contents [1]. Secretarimanber); Assurance. Array Acquel ("Alt 2", Contents [1] .ltPartNumber); Assurance Requel ("TBD", Contents [1]. Vendor Code); Confirm. Eraqual (1m, material [1]. Chanti); Assurance Prejudice (10.0m, material [1]. Pertvolit); Extraordinary ("Notes", Content [1]. Partnotes); Extraordinary ("Details", contents [1]. Part details); Assurance REEqual (2.50m, Contents [1]. Unicast); Assurance First ("A", content [1]. Amendment); }
I often have more than one argument if testing a logical unit of work This is all part of me, so I do not see any problem in it.
Now, I agree that if you get one type of overrides equal
, which makes testing very easy from your other form but In your first test, it seems that you really only want to claim that the result is equal to one expected one, I think there is a rational argument - it is just that you are currently testing it Many mini claims for Obtained are performed.
In some unit test frames, there are ways to test whether two collections are equal - do not use it again, you can easily write one because I did it recently with me because Although NUIT provides a helpful method, its diagnosis is not very helpful. I reffered the code a little bit, basically.
Comments
Post a Comment