I've seen a few questions on here of people asking for criticism of their unit tests. I haven't seem them get closed, so I'd like to do the same.
I whipped up these tests, which I believe are made more readable by using dynamic
, but I was wondering if anyone in the SO community had anything to add.
I know the use of dynamic is for some reason very controversial, and for some reason starts religious wars amongst C# developers. I'm really hoping to avoid that; I'm just trying to write some good tests to help me do my job :)
[TestMethod]
public void TestAllocation() {
SearchView.StubPropertyNumValueThenSetUpSearchView<WellDetail>("TX", Property.WorkingInterestTaxSubtypeId);
Presenter.SetUpPhaseAndFmvValues(Phase.PhaseIdForForRenderAppraiser, 1000);
AddTheseItems(
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can2", MostRecentFmv = 40 },
new { PropNum = "pn1", CAN = "can2", MostRecentFmv = 40 },
new { PropNum = "pn1", CAN = "can2", MostRecentFmv = 40 },
new { PropNum = "pn2", CAN = "can1", MostRecentFmv = 50 },
new { PropNum = "pn2", CAN = "can1", MostRecentFmv = 50 });
Presenter.Process(SearchView, ItemsToProcess);
AssertTheseItemsExist(
new { NumberOfTimes = 4, PropNum = "pn1", CAN = "can1", FmvCalculated = 100 },
new { NumberOfTimes = 3, PropNum = "pn1", CAN = "can2", FmvCalculated = 400 },
new { NumberOfTimes = 2, PropNum = "pn2", CAN = "can1", FmvCalculated = 500 });
}
private void AddTheseItems(params dynamic[] MassUpdateDtos) {
foreach(dynamic item in MassUpdateDtos)
ItemsToProcess.Add(new MassFMVUpdateDTO(new WellDetail() { PropertyNum = item.PropNum, CountyAccountNum = item.CAN }, new FMVHistory(), 0, item.MostRecentFmv));
}
private void AssertTheseItemsExist(params dynamic[] uniqueTargets) {
foreach (dynamic target in uniqueTargets)
Assert.AreEqual(target.NumberOfTimes, ItemsToProcess.Count(f => f.PropertyNum == target.PropNum && f.CountyAccountNum == target.CAN && f.FMV == target.FmvCalculated));
}
Dynamic Testing is a kind of software testing technique using which the dynamic behaviour of the code is analysed. For Performing dynamic, testing the software should be compiled and executed and parameters such as memory usage, CPU usage, response time and overall performance of the software are analyzed.
Unit tests, integration tests, system tests and acceptance tests utilize dynamic testing.
Abstract: Unit testing is used by programmers to discover bugs with least cost. Static unit testing offers the minimum path coverage while dynamic unit testing detects control and data flow problems.
To perform dynamic testing the software should be compiled and run. It includes working with the software by giving input values and checking if the output is as expected by executing particular test cases which can be done with either manually or with automation process.
Sure the use of dynamic reduces the lines of code you need to use. But think about what you want from unit tests first. You want them to tell you where your code goes wrong.
If one of the rows of data you add are wrong, will it tell you which one failed? And if one of the asserts fails, will it tell you which one?
So long as you can get the information you need, you should be fine. So it should tell exactly what went wrong and when it did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With