XUnit si parametrii la functii – clase sau statice?

Mi-am analizat codul pe care l-am scris intr-un proiect de test.

Vroiam sa citesc niste date de test pe un fisier CSV si sa le trimit ca parametrii la test.

Aveam clasa de baza

public class CSVReaderClassData : IEnumerable<object[]>
{
private readonly List<object[]> _data = new List<object[]>();
public CSVReaderClassData(string fileName)
{
var contents = File.ReadLines(fileName);
//skip 1 - the header
contents.Skip(1).ToList().ForEach(it => _data.Add(it.Split(',')));

    }

    public IEnumerator<object[]> GetEnumerator()
    { return _data.GetEnumerator(); }

    IEnumerator IEnumerable.GetEnumerator()
    { return GetEnumerator(); }
}

si apoi alte vreo patru clase derivate( arat doar doua)

class RoboCopyCSV: CSVReaderClassData
{
public RoboCopyCSV(): base("RoboCopyCSV.txt")
{

    
}
}
class XCopyCSV: CSVReaderClassData
{
public XCopyCSV(): base("XCopyCSV.txt")
{

    
}
}

 

Nu intelegeam de ce am facut asa – pina cind am descoperit

[Theory]
[ClassData(typeof(RoboCopyCSV))]
public void TestTimeRoboCopy(string dest, string source, string threadsNumber){
}

[Theory]
[ClassData(typeof(XCopyCSV))]
public void TestTimeXCopy(string dest, string source){

}

Fie faceam asa , fie faceam cu

[PropertyData(nameof(RoboCopyTestData))]

unde RoboCopyTestData era o functie statica care intorcea IEnumerable

Nu stiu de ce, dar intre functii statice si clase …. parca prefer clase ( asta poate insemna ca am depasit programarea modulara. Sa vad cind trec la cea functionala)

Leave a Reply

Your email address will not be published. Required fields are marked *

http://creativecommons.org/licenses/by/4.0/