kentico_jurajo
-
2/3/2014 1:43:42 AM
RE:DI / IoC with page templates and web parts
Hi,
You are right, Kentico does not use a custom page handler factory and you are free to provide your own as mentioned in the linked article. However, I can't stress enough one important fact; there's little value in testing web parts or page templates. The UI tests are difficult to write, they take long time to run, the coverage is low and they tend to be very fragile. To focus on testing your API is much better choice. You are certainly on the right track. I recommend you write an integration test. It requires a test database and you must call the CMSContext.Init method before the actual test runs. Without this call the application wouldn't initialize and you wouldn't be able to use the Kentico API. At least you need to perform the following steps:
• Create a test project. • Add references to the System.Data, System.Xml, CMS.CMSHelper, CMS.DataEngine, CMS.DataProviderSQL, CMS.SettingsProvider, CMS.SiteProvider and CMS.Synchronization assemblies. • Add an application configuration file with a test database connection string.
There's less friction in version 8. You do not need a database as you can mock the database object providers, and there are predefined test suite classes to derive from that shield you from the necessary plumbing. However, better support for testability is currently in scope of version 9.
Best regards, Juraj Ondrus
|