3

When you write a module, you write unit tests (or you should - I don't because I am a bad person, but I want to change - honest).

Should modules generated with Features be unit tested where applicable/possible, or is a suite of Selenium tests enough?

For example, say I have a Feature that has a node type and a couple of user roles and/or permissions for said content type. Is it good practice (or even necessary) for SimpleTests to be written to test creation of my content type?

For clarity, I am aware of Unit test for custom content type, but I am after an answer regarding all unit testable functionality, not just content types.

1 Answer 1

1

The Features module has its own tests that verify that the operations done on a feature (e.g. adding or reverting it) as successful. Drupal already has tests to verify that for example, users with the right permission can read/write/update a node, or that a Drupal variable is effectively saved. The Views module should have its own tests to verify that exporting/importing a views is done correctly.

Apart from those tests, you should not have any reason to write tests for the Feature module, as the existing tests should already covers any possibility. The only case I would write a test for a feature is when the feature is using custom code you wrote.

8
  • 4
    Yes, but here's a counter argument. Suppose that the requirement for a feature includes setting an option in some third party module. That option happens to be the default, so if you forget to set the strongarm value when creating the feature, general testing won't find it. If someone sets another value manually the feature won't show as overridden, even though it should. So failing to test the feature may be a mistake. Apr 11, 2013 at 13:54
  • 1
    You missed my point. A feature is created to meet a requirement, but it's quite possible it doesn't do so, most likely because the user forgot to include an item. So a test to ensure that it does what it's supposed to do is quite logical. You wouldn't be testing code of the Features, module, you'd be testing that the feature had been configured correctly. This can be quite important when a site is worked on by a lot of people: try spotting that a single Strongarm variable has got lost in a merge. Apr 15, 2013 at 7:47
  • 1
    I wouldn't argue that it's always practical or convenient to test features, but good software development practice says that you should. Configuration changes to a system should be both testable and tested. However I am well aware that very few projects always follow good practice, and that includes my own. The OP was asking about good practice so that's how I felt his question should be answered. Apr 15, 2013 at 16:26
  • 1
    To be fair, the type of testing I am talking about is more strictly an integration test, as what it tests for is the effect of a feature on other parts of the system, not the feature in isolation. Apr 15, 2013 at 16:31
  • 1
    I wouldn't propose to test the setting of variable Z per se, rather the effect that has on whatever other modules use it. Apr 15, 2013 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.