Print
Testability Compared

By "testability", we are not speaking in the normal sense of testing the managed beans. Both Pico, Spring and Nuts manage pojos that are unit testable.

By "testability", we mean to verify and test the configuration itself.

When wiring up objects, the dependencies injected into the objects normally affect the behavior of the objects. It'll be more cohesive to put the verification of the behavior and the configuration that causes the behavior together.

When Pico or Yan is wired up in straight Java, this is easy because we can organize the wiring code and verification code in whatever the best way we like.

It becomes a challenge when the configuration is placed in XML. How do we verify the configuration?

Spring provides a dependency checking facility that checks dependencies for each bean. It may be useful, but not really what we are looking for.

Configuration testable in Nuts

In the jfun.yan.xml.nuts.optional package, we stacked around 20 optional Nut classes that can be used to do certain tasks.

For verifying and testing configuration, we have AssertSameNut, AssertNotSameNut, AssertEqualNut, AssertNotEqualNut, PrintNut classes that proved to be useful in testing various Nuts functionalities.

These custom Nut classes can be loaded into xml configuration file using the <nut> tag.

For example, the following code verifies that two components instantiate equal objects:

<module name="test module">
<nut name="assertEqual" class="jfun.yan.xml.nuts.optional.AssertEqualNut"/>
<nut name="print" class="jfun.yan.xml.nuts.optional.PrintNut"/>
<body>
  <sequence id="test.case1">
    <method var="v1" class="Class1" name="method1" params=""/>
    <method var="v2" class="Class2" name="method2" params=""/>
    <assertEqual val1="$v1" val2="$v2"/>
    <print msg="$v1"/>
  </sequence>
</body>

This unit-test-within-configuration is a unique feature introduced by Nuts.

Powered by Atlassian Confluence