© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
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);

    }


    
}
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
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ xUnit - totally isolated serial parameterized tests?
C#CC# / help
3y ago
Catastrophic failure while running xunit tests
C#CC# / help
3y ago
❔ Help needed to clear database with EF between XUnit tests
C#CC# / help
3y ago