I have this method signature: List<ITMData> Parse(string[] lines)
ITMData
has 35 properties.
How would you effectively test such a parser?
Questions:
- Should I load the whole file (May I use System.IO)?
- Should I put a line from the file into a string constant?
- Should I test one or more lines
- Should I test each property of ITMData or should I test the whole object?
- What about the naming of my test?
EDIT
I changed the method signature to ITMData Parse(string line)
.
Test Code:
[Subject(typeof(ITMFileParser))]
public class When_parsing_from_index_59_to_79
{
private const string Line = ".........";
private static ITMFileParser _parser;
private static ITMData _data;
private Establish context = () => { _parser = new ITMFileParser(); };
private Because of = () => { _data = _parser.Parse(Line); };
private It should_get_fldName = () => _data.FldName.ShouldBeEqualIgnoringCase("HUMMELDUMM");
}
EDIT 2
I am still not sure if I should test only one property per class. In my opinion this allows me to give more information for the specification namely that when I parse a single line from index 59 to index 79 I get fldName. If I test all properties within one class I loss this information. Am I overspecifying my tests?
My Tests now looks like this:
[Subject(typeof(ITMFileParser))]
public class When_parsing_single_line_from_ITM_file
{
const string Line = ""
static ITMFileParser _parser;
static ITMData _data;
Establish context = () => { _parser = new ITMFileParser(); };
private Because of = () => { _data = _parser.Parse(Line); };
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
It should_get_fld??? = () => _data.Fld???.ShouldEqual(???);
...
}
TextReader
or anIEnumerable<string>
. (Returning a list is fishy, too, if you can get away with doing the parsing lazily line-by-line.) – Ducharme