The frustration of unit test

    Date: 06/27/05 (C Sharp)    Keywords: google

    I like unit tests. It's cool to be able to try out little bits of your code, and make sure the small parts work before you try making it do larger things. It's good stuff.

    But by god - does it have to be so poorly documented?

    In this case I'm looking at NUnit.Util. This is part of the standard NUnit install, and it contains a bunch of classes - and no documentation on them. I've done searches through google - no documentation found.

    Does this stuff get used?

    What I needed: A way to trap output that is supposed to go to the console so I can make sure that something that writes to it is actually writing what I wanted.

    What I eventually did: I took the NUnit.Util.ConsoleWriter, and inherited from it as below. Then, I passed it in as a TextWriter, which my console app would write to.


    using System;
    using System.Text;
    using System.IO;
    using NUnit.Util;

    namespace moCSCXIImport.Tests
    {
    ///


    /// Summary description for MockConsole.
    ///

    public class MockConsole : ConsoleWriter
    {
    private StringBuilder TextBuffer;

    public MockConsole(TextWriter console) : base(console)
    {
    TextBuffer = new StringBuilder();
    }

    public override void Write(char c)
    {
    TextBuffer.Append(c);
    base.Write(c);
    }

    public override void Write(String s)
    {
    TextBuffer.Append(s);
    base.Write(s);
    }

    public override void WriteLine(string s)
    {
    TextBuffer.Append(s);
    TextBuffer.Append("\n"); // newline
    base.WriteLine(s);
    }

    public string TextWritten
    {
    get { return TextBuffer.ToString(); }
    }

    public long GetTextLength()
    {
    return TextBuffer.Length;
    }

    }
    }


    But I'm sure someone's done something like this before. But why couldn't I *find* it?

    Source: http://www.livejournal.com/community/csharp/31735.html

« Рассылка .Net... || ActiveX, PowerPoint, C# »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home