I am writing some tests at the moment and was wondering if my tests should have dependencies to other methods or duplicated code. Here is a simple example what I mean:
class MyClass{
myArray
initArray(){
//initilize myArray
}
doStuffWithArray(){
//do Stuff with the values of myArray
}
}
Tests:
initArrayTest(){
//test initArray
}
//Option 1:
doStuffWithArrayTest(){
initArray();
//test doStuffWithArray();
}
//Option 2:
doStuffWithArrayTest(){
//init Array myself
//test doStuffWithArray();
}
I have to choose to duplicate my code or to have a dependency to another method which I normally don't need. Maybe this problem looks a bit pointless but imagine the methods have 10 lines of code +. And it would be nice if you don't focus on this specific code and furthermore try to understand the problem in a real project. I Hope you guys get my point.
Aucun commentaire:
Enregistrer un commentaire