C#C
C#3y ago
Spekulant

❔ xUnit tests

using System;
using System.IO;

namespace TestWordCount;

public class WordCounterTests
{
    [Fact]
    public void Test1() {
        var story = """
        Jack and Jill went up the hill.
        """;
        var reader = new StringReader(story);

        var counter = new WordCounter(reader);

        counter.Execute();
        var stringWriter = new StringWriter();
        Console.SetOut(stringWriter);
        counter.WriteResults();
        string allConsoleOutput = stringWriter.ToString();
        Console.WriteLine("Actual Output: " + allConsoleOutput);
        

        Assert.Equal("14\n2", allConsoleOutput);

    }


    
}

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
12
4

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
Was this page helpful?