Difference between revisions of "Unit Testing"
From Opentaps Wiki
Jump to navigationJump to searchm (Protected "Unit Testing": Sysop page [edit=sysop:move=sysop]) |
|||
Line 4: | Line 4: | ||
==How to Write Unit Tests== | ==How to Write Unit Tests== | ||
− | For opentaps 1.0, you would write a set of Junit tests in a class, then add | + | For opentaps 1.0, you would write a set of Junit tests in a class, then define it in an XML testdef file like this: |
+ | <pre> | ||
+ | <test-suite suite-name="entitytests" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
+ | xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/test-suite.xsd"> | ||
+ | <test-case case-name="security-tests"><junit-test-suite class-name="com.opensourcestrategies.crmsfa.test.SecurityTests"/></test-case> | ||
+ | </test-suite> | ||
+ | </pre> | ||
+ | |||
+ | You can define multiple tests per testdef xml file. Then, add the testdef file to your ofbiz-component.xml, like this: | ||
+ | |||
+ | <test-suite loader="main" location="testdef/crmsfa_tests.xml"/> | ||
+ | |||
+ | Then, when you do | ||
+ | $ ant run-tests | ||
+ | your tests will be run. | ||
In opentaps 0.9, you would write your Junit tests class and add your it to the base/config/test-containers.xml file, in the "junit-container" at the bottom, like this: | In opentaps 0.9, you would write your Junit tests class and add your it to the base/config/test-containers.xml file, in the "junit-container" at the bottom, like this: | ||
Line 12: | Line 27: | ||
<property name="entity-test" value="org.ofbiz.entity.test.EntityTestSuite"/> | <property name="entity-test" value="org.ofbiz.entity.test.EntityTestSuite"/> | ||
<property name="service-test" value="org.ofbiz.service.test.ServiceEngineTests"/> | <property name="service-test" value="org.ofbiz.service.test.ServiceEngineTests"/> | ||
− | <property name="crm-security" value="com. | + | <property name="crm-security" value="com.opensourcestrategies.crmsfa.test.SecurityTests"/> <!-- your unit tests --> |
<!-- | <!-- | ||
<property name="usps-test" value="org.ofbiz.shipment.thirdparty.usps.UspsServicesTests"/> | <property name="usps-test" value="org.ofbiz.shipment.thirdparty.usps.UspsServicesTests"/> | ||
Line 21: | Line 36: | ||
Then you would do | Then you would do | ||
$ ant run-tests | $ ant run-tests | ||
− | |||
− | |||
Your tests will run alongside the existing OFBIZ test suites. | Your tests will run alongside the existing OFBIZ test suites. | ||
− | IMPORTANT: | + | '''IMPORTANT''': Use a "test" delegator to point your tests to a separate database, and make sure it is defined in framework/entity/config/entityengine.xml is set to the right database. |
Revision as of 01:25, 21 September 2007
Contents
How to Write Unit Tests
For opentaps 1.0, you would write a set of Junit tests in a class, then define it in an XML testdef file like this:
<test-suite suite-name="entitytests" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/test-suite.xsd"> <test-case case-name="security-tests"><junit-test-suite class-name="com.opensourcestrategies.crmsfa.test.SecurityTests"/></test-case> </test-suite>
You can define multiple tests per testdef xml file. Then, add the testdef file to your ofbiz-component.xml, like this:
<test-suite loader="main" location="testdef/crmsfa_tests.xml"/>
Then, when you do
$ ant run-tests
your tests will be run.
In opentaps 0.9, you would write your Junit tests class and add your it to the base/config/test-containers.xml file, in the "junit-container" at the bottom, like this:
<container name="junit-container" class="org.ofbiz.base.container.JunitContainer"> <property name="base-test" value="org.ofbiz.base.test.BaseUnitTests"/> <property name="entity-test" value="org.ofbiz.entity.test.EntityTestSuite"/> <property name="service-test" value="org.ofbiz.service.test.ServiceEngineTests"/> <property name="crm-security" value="com.opensourcestrategies.crmsfa.test.SecurityTests"/> <!-- your unit tests --> <!-- <property name="usps-test" value="org.ofbiz.shipment.thirdparty.usps.UspsServicesTests"/> <property name="jxunit-test" value="net.sourceforge.jxunit.JXTestCase"/> --> </container>
Then you would do
$ ant run-tests
Your tests will run alongside the existing OFBIZ test suites.
IMPORTANT: Use a "test" delegator to point your tests to a separate database, and make sure it is defined in framework/entity/config/entityengine.xml is set to the right database.