unit-testing

How to create tests for poco objects

Hi, I'm new to mocking/testing and wanting to know what level should you go to when testing. For example in my code I have the following object: public class RuleViolation { public string ErrorMessage { get; private set; } public string PropertyName { get; private set; } public RuleViolation( string errorMessage ) { ...

can some one help me how to use IList in c#

I'm am trying to test wcf method in C#. method return type is ilist. I need to catch that returned data in to an ilist and then i have to retrive each item from ilist. can some one send me a sample code how to do this? ...

Unit Testing and Code Coverage Frameworks for Objective-C?

I'm planning to write couple applications for iPhone and wonder if there are any Unit Testing and Code Coverage Frameworks for Objective-C? ...

Python Pre-testing for exceptions when coverage fails

I recently came across a simple but nasty bug. I had a list and I wanted to find the smallest member in it. I used Python's built-in min(). Everything worked great until in some strange scenario the list was empty (due to strange user input I could not have anticipated). My application crashed with a ValueError (BTW - not documented in t...

Mock dll methods for unit tests

I am trying to write a unit test for a method, which has a call to method from dll. Is there anyway i can mock the dll methods so that i can unit test? public string GetName(dllobject, int id) { var eligibileEmp = dllobject.GetEligibleEmp(id); <---------trying to mock ...

Python unit test. How to add some sleeping time between test cases?

I am using python unit test module. I am wondering is there anyway to add some delay between every 2 test cases? Because my unit test is just making http request and I guess the server may block the frequent request from the same ip. ...

How can I start a TCP server in the background during a Perl unit test?

I am trying to write a unit test for a client server application. To test the client, in my unit test, I want to first start my tcp server (which itself is another perl file). I tried to start the TCP server by forking: if (! fork()) { system ("$^X server.pl") == 0 or die "couldn't start server" } So when I call make test after pe...

Working effectively with unit tests / Anyone tried the in-assembly approach?

I'm trying to re-introduce unit testing into my team as our current coverage is very poor. Our system is quite large 40+ projects/assemblies. We current use a project named [SystemName].Test.csproj were all the test code is dumped and organised to represent the namespaces using folders. This approach is not very scalable and makes it di...

Tips and tricks for test-first development.

Just read this blog post - Help! I’m Terrible At Migrating/Restructuring Code In A Test-First Manner. I've had similar experiences, and thought I'd try an open it up to the wider community ... ...

How to unit test control library?

I program simple control library that checks user input from text and format the input.I want to make a unit test.How can I do that ? ...

Mocking a concrete class : templates and avoiding conditional compilation

I'm trying to testing a concrete object with this sort of structure. class Database { public: Database(Server server) : server_(server) {} int Query(const char* expression) { server_.Connect(); return server_.ExecuteQuery(); } private: Server server_; }; i.e. it has no virtual functions, let alone a well-defined int...

python unittest howto

I`d like to know how I could unit-test the following module. def download_distribution(url, tempdir): """ Method which downloads the distribution from PyPI """ print "Attempting to download from %s" % (url,) try: url_handler = urllib2.urlopen(url) distribution_contents = url_handler.read() url_handle...

Ruby: How do I define a datetime field in YAML?

I'm creating test data for a Rails app. How do I define the value for a datetime field in YAML? ...

How to change the date/time in Python for all modules?

When I write with business logic, my code often depends on the current time. For example the algorithm which looks at each unfinished order and checks if an invoice should be sent (which depends on the no of days since the job was ended). In these cases creating an invoice is not triggered by an explicit user action but by a background j...

Is a class that is hard to unit test badly designed?

I am now doing unit testing on an application which was written over the year, before I started to do unit-testing diligently. I realized that the classes I wrote are hard to unit test, for the following reasons: Relies on loading data from database. Which means I have to setup a row in the table just to run the unit test (and I am not...

.NET equivalent of httpunit

I will openly admit that I fall on the side of Test Driven Development. I have run into a situation that I would like to test, but I haven't found a good way to do so. I have been working in ASP.NET MVC and I would like to test that the parts of code that I am putting into the view layer (and I know that I need to keep that as minimal a...

Multiple Silverlight Unit Test Projects in Solution

I am building out a number of Silverlight 4.0 libraries that are part of the same solution. I like to break them into separate projects and have a Unit Test project for each: SolutionX -LibraryProject1 ---Class1.cs ---Class2.cs -LibraryProject1.Test ---Tests1.cs ---Tests2.cs -LibraryProject2 ---Class1.cs ---Class2.cs ---CLass3.cs -Libr...

Does ActiveRecord make Ruby on Rails code hard to test?

I've spent most of my time in statically typed languages (primarily C#). I have some bad experiences with the Active Record pattern and unit testing, because of the static methods and the mix of entities and data access code. Since the Ruby community probably is the most test driven of the communities out there, and the Rails ActiveReco...

UnitTest++ constructing fixtures multiple times?

I'm writing some unit tests in UnitTest++ and want to write a bunch of tests which share some common resources. I thought that this should work via their TEST_FIXTURE setup, but it seems to be constructing a new fixture for every test. Sample code: #include <UnitTest++.h> struct SomeFixture { SomeFixture() { // this line is...

Running a JUnit4 test - from a java program

I was wondering how to run some JUnit4 test inside a java program. Basically - depending on some conditions during runtime I need to decide which test runner to use. Using Junit3 I could override runTest method from TestCase class - but in JUnit4 tests do not extend TestCase class so I have nothing to override... Is there maybe some meth...