NH ProfA testing story

time to read 3 min | 428 words

Remember that I mentioned the difference about working and production quality?Icon

One of the things that separate the two that in production quality software, you don't need to know which buttons not to push. Here is a simple example. For a while now, if you tried to bring up two instances of NH Prof, the second one would crash. That wasn't something that you really want to show the users. Today I got back to doing NH Prof stuff, getting it ready for public beta, and I decided that the first thing to do was to tackle this easy feature.

Doing this is actually not an issue, testing this, however, was a problem. I have two application instances and four layers to go through. Here is the first test:

public void When_creating_two_instances_of_application_will_tell_the_other_to_pop_up()
var bus = MockRepository.GenerateStub<IBus>();
var listener = new NHibernateAppenderRemotingLoggingEventListener(bus);

try { var anotherBus = MockRepository.GenerateStub<IBus>(); var anotherListener = new NHibernateAppenderRemotingLoggingEventListener(anotherBus);
Assert.Fail("Exception was expected");
catch (AnotherApplicationIsAlreadyRunningAndControlWasMovedToItException)

bus.AssertWasCalled(x => x.Publish(null),
options => options.Constraints(Is.TypeOf<BringApplicationToFront>())

The logging event listener is the reason that we can't bring up two instances of this. We use this to listen to running applications, and having several of the profilers running at one time isn't going to be helpful. And just to deal with the nitpickers, the four layers I mentioned are: Communication layer, backend, front end, actual user interface.

Here is an example that tests communication between the back end and the front end:

public void When_bring_up_to_front_message_is_publish_observer_should_raise_event_for_UI()
var facility = new BusFacility();
var observer = new ModelBuilderObserver(action => action());
bool wasBroughtToFront = false;
observer.ShouldBringApplicationToFront += () => wasBroughtToFront = true;
facility.Bus.Publish(new BringApplicationToFront());

As for the actual UI code, I am not sure how to test that. I did a manual test, but I am not sure that I am happy about this. Then again, we are talking about testing this line of code:

observer.ShouldBringApplicationToFront += () => Activate();

I can just test that the event was subscribed to, but I don't really see this as valuable.

More posts in "NH Prof" series:

  1. (09 Dec 2010) Alert on bad ‘like’ query
  2. (10 Dec 2009) Filter static files
  3. (16 Nov 2009) Exporting Reports
  4. (08 Oct 2009) NHibernate Search Integration
  5. (19 Aug 2009) Multiple Session Factory Support
  6. (07 Aug 2009) Diffing Sessions
  7. (06 Aug 2009) Capturing DDL
  8. (05 Aug 2009) Detect Cross Thread Session Usage
  9. (22 May 2009) Detecting 2nd cache collection loads
  10. (15 May 2009) Error Detection
  11. (12 May 2009) Queries by Url
  12. (04 Feb 2009) View Query Results
  13. (18 Jan 2009) Superfluous <many-to-one> update
  14. (18 Jan 2009) URL tracking
  15. (10 Jan 2009) Detecting distributed transactions (System.Transactions)
  16. (06 Jan 2009) The Query Cache
  17. (05 Jan 2009) Query Duration
  18. (24 Dec 2008) Unbounded result sets
  19. (24 Dec 2008) Row Counts