unit-testing

TDD Anti-patterns catalogue

anti-pattern : there must be at least two key elements present to formally distinguish an actual anti-pattern from a simple bad habit, bad practice, or bad idea: Some repeated pattern of action, process or structure that initially appears to be beneficial, but ultimately produces more bad consequences than beneficial results, and A ref...

Does anyone have metrics on the utility of formal Unit Testing?

Does anyone have metrics on the utility of formal Unit Testing? I see a lot of attention being paid to unit testing tools and I was curious why? I stopped formal unit testing over 5 or 6 years ago and the net gain in productivity seems quite high. I stopped unit testing because I noticed that it never caught anything - let alone anyth...

How should methods updating database tables be unit tested?

I have an application that is database intensive. Most of the applications methods are updating data in a database. Some calls are wrappers to stored procedures while others perform database updates in-code using 3rd party APIs. What should I be testing in my unit tests? Should I... Test that each method completes without throwin...

Testing Events from Objects

I have been trying to get more in to TDD. Currently keeping it simple with lots of Debug.Asserts in a console application. Part of the tests I wanted to complete was ensuring that events were raised from the object, the correct number of times, since client code will depend on these events. So, I began thinking about how to test the ev...

Do you use TestInitialize or the test class constructor to prepare each test? and why?

This question regards unit testing in Visual Studio using MSTest (this is important, because of MSTest's execution order). Both the method marked [TestInitialize] and the test class constructor will run before each test method. So, the question is, what do you tend to do in each of these areas? Do you avoid performing certain activities...

Programatically calculate the size of a value type

I'm writing a unit test for a method that packs boolean values into a byte. The various bit locations are determined by the value of an enum, which only has 5 values right now, but it's conceivable (though extremely unlikely) that this number could go to 9. I'd like a simple test along the lines of: private byte m_myNum; enum MyEnum {...

Unit testing code that sends JMS messages

i have a class that after it does some stuff, sends a JMS message. i'd like to unit test the "stuff", but not necessarily the sending of the message. when i run my test, the "stuff" green bars, but then fails when sending the message (it should, the app server is not running). what is the best way to do this, is it to mock the message qu...

How can I use Mock Objects in my unit tests and still use Code Coverage?

Presently I'm starting to introduce the concept of Mock objects into my Unit Tests. In particular I'm using the Moq framework. However, one of the things I've noticed is that suddenly the classes I'm testing using this framework are showing code coverage of 0%. Now I understand that since I'm just mocking the class, its not running the ...

Functional testing of a RESTful POST in Ruby on Rails

I'd like to write a functional test of a RESTful web service I'm working on in a Ruby on Rails app. The test is of a POST request where the body of the request is a plain XML doc and not a form. Any pointers on how to do this? The problem I'm encountering is how to specify the body XML in the call to the post method. ...

What is the best Nunit test runner out there?

Having recently gotten into test driven development I am using the Nunit test runner shipped as part of resharper. It has some downsides in terms of there is no shortcut to run tests and I have to go looking for the Nunit test runner to invoke it using the mouse. It has a nice GUI and shows the results as part of the IDE well. What do o...

NUnit with night build, how to get errors easily?

We have a lot of unit tests but they aren't run every night. I have setup some batch files that compile all the code from the SVN repository and I would like to run NUnit. This is not a big problem because I can call it from the batch file after the compilation BUT the output is stored in the network drive and I need to open it every mor...

How to integration-test a network application in C

I've never managed to move from unit-testing to integration-testing in any graceful or automated way when it comes to network code. So my question is: Given a simple single-threaded client/server based network application, how would you go about integrating both client and server into your currently favorite testing suite (I currently u...

How can I implement TDD in Perl?

We're using mod_perl to produce data in XML and later to be converted into HTML via XSLT, and the database is in MySQL. Our OS is Unix. So I've been reading about how cool and powerful TDD is in .NET, Java with all the available frameworks. I've even tested NUnit before and I kind of like it. You can write the test once and use it prett...

IronPython For Unit Testing over C#

We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code. Is it ideal choice to write unit test cases in IronPython instead of C#?...

Is there any way to use diag() from Test::More without planning?

I'm writing some tests in Perl which have a fair amount of set up. This setup all lives in a module that the test scripts use. I want to be able to print some diagnostics from the module, and intended to use the diag function from Test::More. Problem is, when you use Test::More, it writes the plan so I get You tried to plan twice at...

Automatically generating test cases

I'm writing a script a script to test a third party XML interface, using the python unittest module. First of all, is this a reasonable use of unittest, using an API we wrote, but actually testing the interface it's connecting to? Secondly, I have a huge list of fields I want to test. The code to test each field is identical. I want to...

Unit Testing in web applications that use databases

Hi, I am building a web application that uses the database for Users, Security/roles, and to store content. It seems a little daunting to me to begin on the road of unit testing because I have to make sure my database has been initialized properly for my tests to run. What are common practices to help in this regard? i.e. while devel...

How has unit testing made your life better ?

Ok let me be honest, I haven't more than 10 unit tests in my life probably. I am embarking on a new project, and being the sole programmer means I should be scared ... very scared. The idea that I can pseudo guarantee that my software works brings about a sense of joy. Sure I will miss a ton of cases where I should have tested, but ...

testing classes

I put together a class yesterday to do some useful task. I started alpha testing, and at some point realized I was adding alpha test related methods to the class itself. It hit me that they don't belong there. After a bit of head scratching I derived a test class from the base class that has access to the protected members as well. ...

Minimum NUnit binaries for an OSS project

Open Source projects that ship with unit tests based on NUnit also usually ship the NUnit runners and accompanying binaries. For NUnit 2.4.8, distributing its bin directory verbatim with the actual project amounts to 46 files and a blank addins directory. What would be the minimum set of files needed if all one wanted was to distribute t...