Javaв„ў EE 5 Tutorial, The (3rd Edition)

Some tips and techniques for using NUnit, the testing framework used in this book.

Testing: A Core Practice

As you read this book, you ll see that we do a lot of testing. We write most of our tests before we write the code, one test at a time. A little test, a little code to make it work, and so on. We work that way for some good reasons, which you ll see as we go along:

But I m not here to sell testing; I m here to tell you how we do it. Let s move along. We re going to start here with a moderately advanced example using regular expressions and the .NET Regex class. In the next chapter, which relates our first real efforts on the XML Notepad, you ll see that we return to an approach that is even simpler than Regex. Here, we re just experimenting with NUnit and learning a bit about Regex.

As we work with the XML Notepad, I m expecting that we ll have to look at text strings a lot and figure out whether they have any XML tags in them. XML tags, as you probably know, come in matched pairs of strings embedded in squiggles: <SomeTag>like this</SomeTag>. Now .NET includes some powerful features for working with XML, and later on in the book we ll look at some of them. But we re here to learn C#, and part of that will mean digging down a little deeper into how things work. Since C# has some powerful support for regular expressions, I decided to learn a little about them.

Often when I experiment with something new, I just write some throwaway code that prints results to the console. Some good angel inspired me to do it this time by writing tests using NUnit, the .NET testing framework. The result, as you ll see, is some permanent information instead of just something that goes into my head, perhaps later to be forgotten. And something that others can learn from, making their job just a bit easier. Read on.

Категории