unit-testing

How to test a persistence layer correctly?

Hi! I read the Book NHibernate in Action and there it is speaking about testing the persistence layer/data abstraction layer. You can test two ways. The mapping-test and the persistence logic-test. Accoring to the book testing the mapping means that entities are correctly loaded and saved. But what's about update's and delete's? By no...

two-way list comparison in C# unit test

In my C# unit tests, I often query for a list of rows based on a list of IDs. I then want to ensure that 1) for all the IDs, there was at least one row found that has that ID and 2) for all the returned rows, each row has an ID that is in the list of IDs to find. Here is how I usually ensure that: Assert.IsTrue(ids.All( id => resu...

Implementing Unit Testing on the iPhone

Hi, So I've followed this tutorial to setup unit testing on my app when I got a little stuck. At bullet point 8 in that tutorial it shows this image, which is what I should be expecting when I build: However this isn't what I get when I build. I get this error message: Command /bin/sh failed with exit code 1 as well as the error mes...

boost-test application initialisation

I'm just getting stated with boost-test and unit testing in general with a new application, and I am not sure how to handle the applications initialisation (eg loading config files, connecting to a database, starting an embedded python interpretor, etc). I want to test this initialisation process, and also most of the other modules in t...

Django - testing of different visual blocks

I have some the page elements split into separate visual blocks. I am currently integrating the front end htmls from the designer, so it is important for me to test how they appear in the browser individually (each block). What is the simplest way I can implement this using django-testing? I know I can create a view with all the block...

What techniques can be used to make writing tests more interesting?

I must admit that I often struggle with practising Test-Driven Development. In spite of using Ruby on Rails which makes TDD super easy because it's baked-in, I find writing tests to be so boring! It's like dental flossing; I know that I should do it but struggle to muster much enthusiasm. What techniques do you use to make writing test...

How to throw exception in new rhino mocks 3.5

Hi Guys, I am using rhino mocks 3.5 and am trying to throw an exception in my expectation to test some functionality in my catch block. But for some reason it is not throwing the exception. _xyz.stub(x => x.function(string)).throw(new exception("test string")); So, I am stubbing out the call to the function to throw exception but it...

Shoulda: Test validates_presence_of :on => :update

I'm using Shoulda in combination with Test::Unit on one of the projects I work on. The issue I'm running into is that I recently changed this: class MyModel < ActiveRecord::Base validates_presence_of :attribute_one, :attribute_two end to this: class MyModel < ActiveRecord::Base validates_presence_of :attribute_one validates_pr...

DeploymentItem Attribute causes all tests in test class to fail with error "Unable to create instance of class [TestClass]"

Hi Everyone. I'm getting a strange error when I try to run a set of unit tests where the class has a DeploymentItem attribute. The unit testing solution has 2 test classes, one to test business logic which I'll refer to as 'class a' (this one works fine regardless) and one to test reading of data from the DeploymentItem file which I'll...

Mobile Emulator Launched for non-mobile unit tests

I have a Compact Framework Project that has two Unit Test projects with it in the solution. One is a Smart Device Unit Test Project (needs the emulator to run). The other is a normal Unit Test Project. The normal Unit Test Project runs fine on my machine and on the build machine, but on my co-worker's machine it tries to launch the em...

Should I unit test my JavaScript?

I'm curious to if it would be valuable, I'd like to start using QUnit, but I really don't know where to get started. Actually I'm not going to lie, I'm new to testing in general, not just with JS. I'm hoping to get some tips to how I would start using unit testing with an app that already has a large amount of JavaScript (ok so about 50...

JUnit Servlets testing with jndi lookup for the datasource

How to make unit test of servlets which uses jndi for lookup of datasource (JDBC) ? ...

Spring configuration for embedded H2 database for tests

What does your Spring configuration for a datasource with embedded h2 database that you use for integration (JUnit-)tests look like? My first try with a SingleConnectionDataSource basically worked, but failed on more complicated tests involving suspended transactions. You might start h2 in tcp based server mode as well, but this is proba...

C#: How to test for StackOverflowException

Say you have a method that could potentially get stuck in an endless method-call loop and crash with a StackOverflowException. For example my naive RecursiveSelect method mentioned in this question. Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the correspondin...

Ruby Unit Test : Is this a Valid (well-formed) XML Doc ?

I'm creating an XML document: I want to unit test at least to make sure it's well-formed. So far, I have only been able to approximate this , by using the 'hasElements' in the REXML library. Is there a better way ? Preferably using built-in libraries (I mean libraries that ship with the standard Ruby 1.8.x distro). require "test/unit"...

assertRaises just catches base exception

I'm running into a strange problem when using unittest.assertRaises. When executing the code below I get the following output: E ====================================================================== ERROR: testAssertRaises (__main__.Test) ---------------------------------------------------------------------- Traceback (most recent call...

iPhone unit testing: Symbols not found when calling custom code

I'm trying to set up unit testing for my iPhone application. I followed the Apple Unit Testing documentation through and that woked fine, but as soon as I added another class in to that test, I get the following error: "_OBJC_CLASS_$_RootViewController", referenced from: __objc_classrefs__DATA@0 in AppDelegateTests.o ld: symbol(...

Rails unit tests: How to add my own output to unit test results

Hi, When running Rails unit tests I get output specifying line numbers and methods when a test fails, e.g.: 1) Failure: test_05_photo_tag_add_remove(TC_javascript02Test) [./helper/helper.rb:6:in `handle_assert' ./helper/helper.rb:17:in `check_not_string' ./helper/helper.rb:134:in `check_for_ajax_remove_string' javas...

How to unit test code that is highly complex behind the public interface

I'm wondering how I should be testing this sort of functionality via NUnit. Public void HighlyComplexCalculationOnAListOfHairyObjects() { // calls 19 private methods totalling ~1000 lines code + comments + whitespace } From reading I see that NUnit isn't designed to test private methods for philosophical reasons about what unit ...

Unit testing domain objects

We have a requirement to add an event reminder when a user enters their email address on an event page. Event is another domain object. Our initial thought was to create a Customer domain object and related CustomerService: public class CustomerService { public void AddEventReminder(string emailAddress, int eventId) { var cus...