TDD - Unit test modules

Topics: Customizing Orchard, General, Troubleshooting, Writing modules
Jul 15, 2012 at 10:17 PM


I want to use unit test to debug our orchard modules. the idea being we write the test to prove the bug, we fix the bug and use the unit test to prove the bug has been fixed.

basically I have an exception that throws in a service class while accessing a repository (database). I have tried to write a unit test similar to the MembershipServiceTests, but I need to connect to and existing orchard database and query data in the same way that orchard does when it is running.

Has any one done/tried to set up orchard in a unit test, to be able to do as described above, or does any one knows how to do this? if there is then please can you help.




Jul 16, 2012 at 8:25 AM

Unit testing is not very simple due to the many services used in Orchard. And you don't want to query a real database I think, just an ad-hoc one. Have a look at the test suite of my Combinator module. It has some simple examples. For unit testing code that uses a DB, see this test. Pay attention to the loads of references the test project has.

Jul 17, 2012 at 10:31 AM

Hello Piedone, Thank you for getting back so quick. I will have a look at the combinator module, but I will need to connect to a real database to recreate the error.

You are right in you first statement orchard is not very simple due to the many services, I spent a long time registering objects with autofac to try an mimic orchard and with not much success.

Is there a way to run orchard and attach the unit test to the process? a bit like how you can attach the debugger to sites running on iis.

Thanks for your time.

Jul 17, 2012 at 10:49 AM

I don't think such an "attaching" is possible (and I don't really understand what the purpose of it would be).

Jul 17, 2012 at 11:04 AM

Well, actually, take a look at the spec folder in the solution. Those tests run by driving the real app.