developing a unit testing API

HI, I have been assigned a task of exploring unit testing using tools available in the market. My question is how do i write an API that would help in writing unit test cases. Example i can use nunit to write something like this to check whether file exists in the given location.

<Test()> _
   Public Sub CheckOutputFileInfo()
    ReportPath = "D:temp\test.txt"
    Dim result As Boolean
    result = File.Exists(ReportPath)
    Assert.IsTrue(result)
End Sub

I understand this is not the best example but my question is how do i incorporate nunit and develop an API so that other developers/testers can write test cases without bothering about to learn about nunit. FYI I have never written an API this will be my first shot at it. Any recommendations on where to start?? thanks

Answers


Your example isn't strictly a unit test as it hits the file system.

A test is not a unit test if:

  1. It talks to the database
  2. It communicates across the network
  3. It touches the file system
  4. It can't run at the same time as any of your other unit tests
  5. You have to do special things to your environment (such as editing config files) to run it.

I would advise you learn Unit Test best practices and patterns before starting to try to make your developers start unit testing. From experience someone needs to champion unit testing having fully grasped it themselves. It will save you a lot of headaches in the long run.

Here is an excellent book to get you started:

http://artofunittesting.com/


I think you're better off letting the developers use nUnit. It's already nicely designed and flexible. If you want to make life easier for your developers, try building some helper classes that set up test objects and sample data in configurations that are needed by many different tests. Maybe try something like the Creation Method pattern. That's from a really good book called xUnit Test Patterns that describes lots of ways to make test code easier to write, read, and maintain. Most of the book is available online, and the Brief Tour is a good place to start.


Why would you want to do that? NUnit and most alternatives are really simple to learn and use. The challenge in writing unit tests is not mastering the api, but rather to write good tests and testable code.

To use NUnit efficiently you only need to know the Test and TestFixture and SetUp attributes and to know the available asserts in the Assert class. It is really simple!

So I would recommend you focus on how to write good tests and how to write code that is easy to test. Both topics are challenging and there is much to learn.


Need Your Help

finder_sql does not parse string with Rails

ruby-on-rails ruby-on-rails-3 postgresql activerecord finder-sql

I have the problem that the query I use for finder_sql is not parsed correctly before it is handed over to PostgreSQL resulting in a database syntax error.

Extending the user entity of ZfcUserDoctrineORM in ZF2

doctrine2 zend-framework2 zfdoctrine

I'm quite new to ZF2. I have a bunch of doctrine entities from my project in ZF1, one being a User entity.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.