❔ xUnit tests
i have this code that has function execute it reads text and appends the words in a paragraph into a list.
then a function write results it writes the results onto a commandline
for example
the code alone works perfectly fine when im debugging the xunit tests it execute counts the words correctly but when the writeResults function starts the values in the list are empty
10 Replies
I probably found the error the var story does not have EOF thing at the end that is causing an issue
it doesnt work when i have it declared like this
or this but only when like this
but i would like to use the first method beucase i want use test cases when there are
something like this
Is there any way that i can fix this
First, its unusual to test output rather than data. If you structured your code so your
WordCounter
exposed its count as an int property or return value, this would be trivial to test.
Second, you redirect the console output in your test, then without resetting it you do Console.WriteLine
again.
a unit test should never write anything to stdout anyways, so thats just.. wrong
you do the thing, you assert its value. thats it.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.what if my normal code writes thing in the console if the data is wrong
It shouldn't really, thats a presentation specific task
I get a strong feeling you didn't read all my 4 messages above before asking thou
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.