as exercise wrote selectionsort , mergesort class , of course felt should have unit tests them! briefly, classes selectionsort , mergesort this:
public interface isort { void sort(int[] array); } public class mergesort : isort { public void sort(int[] array) { mergesortimplementation(array,0,array.length-1) ; } // mergesortimplementation left off brevity } public class selectionsort : isort { public void sort(int[] array) { selectionsortimplementation(array); } }
for unit tests, had test class each class, realized doing same tests mergesort , selectionsort, , i'm planning on adding different types of sort. made base class , had test classes merge , selction sort inherit it.
public class sortingtests { protected isort _sortroutine = null; [testmethod] public void sort2itemstest() { int[] array = new int[] { 3, 2 }; _sortroutine.sort(array); (int = 0; < array.length - 1; i++) { assert.istrue(array[i] <= array[i + 1]); } } // many more test omitted brevity } [testclass] public class selectionsorttests : sortingtests { [testinitialize] public void initialize() { _sortroutine = new selectionsort(); } } [testclass] public class mergesorttests : sortingtests { [testinitialize] public void initialize() { _sortroutine = new mergesort(); } }
this works great , it's nice when want add new test, add base class. there problems. in test window, end repeated names each test. see 2 copies of sort2itemstest example.
is there way force testing framework rename tests or give identifying info can tell sort2itemstest mergesort , selection sort?
i suppose can have stub methods in mergesorttests , selectionsorttests call
base.sort2itemstest();
but seems lot of typing.
thanks, dave
Comments
Post a Comment