Organization of Tests

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Organization of Tests

Erwin Penner
Hello everybody,

I would like to create unit and integration tests for my custom modules in OFBiz.
Unfortunately, information on this subject is sparse.
For this reason, I checked how it is currently solved in the OFBiz modules.
I'll explain what it's about first. At the end of the mail I have some questions.

Using the example of the base or common modules in the OFBiz framework, simple unit tests can be found in a separate test source folder.
src/test/java

There are also test classes (presumably integration tests) in
base/src/main/java/org/apach /ofbiz/base/test
common/src/main/java/org/apache/ofbiz/common/test

In the base module there are further test classes in
base/src/main/java/org/apache/ofbiz/base/util/string/test

So, I thought simple unit tests should be in the separate test source folder and integration tests under src/main/java/.../test

Additionally, I found this (old) Confluence entry and was a bit confused:
https://cwiki.apache.org/confluence/display/OFBIZ/Code+and+test+separation+for+Apache+OFBiz

My questions are:
- Which test classes belong where?
- Is the current directory structure for tests the final solution or an incomplete refactoring?
- Could/Should all tests (unit and integration tests) be maintained in /src/test/?
- Which test classes must be described in the xml-definition under /testdef ? (My impression so far is that the OFBiz modules only list classes for integration tests.)
- Should I use the ext-test-reader in my custom ofbiz-component.xml to load data for integration tests?
- Can I define a different data source for the test delegator than for the default delegator?
Because a comment in the entityengine.xml says "Be sure that your default delegator (or the one you use) uses the same datasource for test."

Thanks in advance! I look forward to your answer/s! :-)

Erwin
Reply | Threaded
Open this post in threaded view
|

Re: Organization of Tests

c.schinzer-2
Hello,


definitely I am interested and also would like to work against an aligned
standard. For example I found the issue of missing unit tests when
refactoring some simple methods to groovy (I promise to finish and submit
my started jira tickets in the upcoming Community Days). And I also asked
myself the same questions as you do. For the time being I have just guessed
where to place them, but yet a better approach would be to document
practice with this somewhere and track improvements in Jira.

I also would support unit testing from integration testing, which comes
along with a definition of unit of course. I prefer the definition of a
class method as a unit over the class itself as a unit, but I am open to
arguments.

My 2 cents.
Warm regards


Carsten

Am Do., 20. Mai 2021 um 15:51 Uhr schrieb Erwin Penner <
[hidden email]>:

> Hello everybody,
>
> I would like to create unit and integration tests for my custom modules in
> OFBiz.
> Unfortunately, information on this subject is sparse.
> For this reason, I checked how it is currently solved in the OFBiz modules.
> I'll explain what it's about first. At the end of the mail I have some
> questions.
>
> Using the example of the base or common modules in the OFBiz framework,
> simple unit tests can be found in a separate test source folder.
> src/test/java
>
> There are also test classes (presumably integration tests) in
> base/src/main/java/org/apach /ofbiz/base/test
> common/src/main/java/org/apache/ofbiz/common/test
>
> In the base module there are further test classes in
> base/src/main/java/org/apache/ofbiz/base/util/string/test
>
> So, I thought simple unit tests should be in the separate test source
> folder and integration tests under src/main/java/.../test
>
> Additionally, I found this (old) Confluence entry and was a bit confused:
>
> https://cwiki.apache.org/confluence/display/OFBIZ/Code+and+test+separation+for+Apache+OFBiz
>
> My questions are:
> - Which test classes belong where?
> - Is the current directory structure for tests the final solution or an
> incomplete refactoring?
> - Could/Should all tests (unit and integration tests) be maintained in
> /src/test/?
> - Which test classes must be described in the xml-definition under
> /testdef ? (My impression so far is that the OFBiz modules only list
> classes for integration tests.)
> - Should I use the ext-test-reader in my custom ofbiz-component.xml to
> load data for integration tests?
> - Can I define a different data source for the test delegator than for the
> default delegator?
> Because a comment in the entityengine.xml says "Be sure that your default
> delegator (or the one you use) uses the same datasource for test."
>
> Thanks in advance! I look forward to your answer/s! :-)
>
> Erwin
>
Reply | Threaded
Open this post in threaded view
|

Re: Organization of Tests

Nicolas Malin-2
HI both,

Currently I work with Gil for a customer site to different process for
implement some integration and unit test dedicate to business case.

We will try to share some tips on the following weeks.

Nicolas

On 20/05/2021 20:46, Carsten Schinzer wrote:

> Hello,
>
>
> definitely I am interested and also would like to work against an aligned
> standard. For example I found the issue of missing unit tests when
> refactoring some simple methods to groovy (I promise to finish and submit
> my started jira tickets in the upcoming Community Days). And I also asked
> myself the same questions as you do. For the time being I have just guessed
> where to place them, but yet a better approach would be to document
> practice with this somewhere and track improvements in Jira.
>
> I also would support unit testing from integration testing, which comes
> along with a definition of unit of course. I prefer the definition of a
> class method as a unit over the class itself as a unit, but I am open to
> arguments.
>
> My 2 cents.
> Warm regards
>
>
> Carsten
>
> Am Do., 20. Mai 2021 um 15:51 Uhr schrieb Erwin Penner <
> [hidden email]>:
>
>> Hello everybody,
>>
>> I would like to create unit and integration tests for my custom modules in
>> OFBiz.
>> Unfortunately, information on this subject is sparse.
>> For this reason, I checked how it is currently solved in the OFBiz modules.
>> I'll explain what it's about first. At the end of the mail I have some
>> questions.
>>
>> Using the example of the base or common modules in the OFBiz framework,
>> simple unit tests can be found in a separate test source folder.
>> src/test/java
>>
>> There are also test classes (presumably integration tests) in
>> base/src/main/java/org/apach /ofbiz/base/test
>> common/src/main/java/org/apache/ofbiz/common/test
>>
>> In the base module there are further test classes in
>> base/src/main/java/org/apache/ofbiz/base/util/string/test
>>
>> So, I thought simple unit tests should be in the separate test source
>> folder and integration tests under src/main/java/.../test
>>
>> Additionally, I found this (old) Confluence entry and was a bit confused:
>>
>> https://cwiki.apache.org/confluence/display/OFBIZ/Code+and+test+separation+for+Apache+OFBiz
>>
>> My questions are:
>> - Which test classes belong where?
>> - Is the current directory structure for tests the final solution or an
>> incomplete refactoring?
>> - Could/Should all tests (unit and integration tests) be maintained in
>> /src/test/?
>> - Which test classes must be described in the xml-definition under
>> /testdef ? (My impression so far is that the OFBiz modules only list
>> classes for integration tests.)
>> - Should I use the ext-test-reader in my custom ofbiz-component.xml to
>> load data for integration tests?
>> - Can I define a different data source for the test delegator than for the
>> default delegator?
>> Because a comment in the entityengine.xml says "Be sure that your default
>> delegator (or the one you use) uses the same datasource for test."
>>
>> Thanks in advance! I look forward to your answer/s! :-)
>>
>> Erwin
>>
Reply | Threaded
Open this post in threaded view
|

Re: Organization of Tests

Gil Portenseigne
Hello,

Please find answers below :

- Which test classes belong where?

There are two Different types of test (not mentioning selenium webdriver
test)

* Unit test :

Should be quick since compiled and executed at launch of the
application, via the gradle tasks :compileTestJava and
:compileTestGroovy, the :test task.

Those unit tests are today present in OFBiz components src/test/java and
src/test/groovy directory.

Gradle is doing the job to detect, compile and execute them, since those
tests are standalone, and do not need OFBiz and database to be launched


* Integration test

They are defined in OFBiz component testdef directory, since OFBiz need
to be configured and launched for them to be executed.

These are currently quite long to run, so must be explicitly executed by
the user with the task :testIntegration.

The other way to execute them is to use webtools screens :

https://demo-trunk.ofbiz.apache.org/webtools/control/TestSuiteInfo?compName=accounting

(we have some improvements waiting to be contributed)

They can be written in simple, groovy or java language :

         <junit-test-suite
class-name="org.apache.ofbiz.base.util.test.UtilPropertiesTests"/>
         <groovy-test-suite name="simple"
location="component://base/groovyScripts/test/SimpleTests.groovy"/>
         <simple-method-test
location="component://accounting/minilang/test/AutoAcctgTransTestsSales.xml"/>

And those are located in src / groovyScripts / minilang directory, in
package like classification terminated by "test"



- Is the current directory structure for tests the final solution or an
incomplete refactoring?

I think that the refactoring is not done, and we could agree to make it
happen.

- Could/Should all tests (unit and integration tests) be maintained in
/src/test/?

That should be possible with some gradle configuration to ignore
integration test in this directory. To be discussed.

- Which test classes must be described in the xml-definition under
/testdef ? (My impression so far is that the OFBiz modules only list
classes for integration tests.)

True

- Should I use the ext-test-reader in my custom ofbiz-component.xml to
load data for integration tests?

To load data for integration test, in testdef, you can specify specific
files to be loaded :

     <test-case case-name="accounting-tests-data-load">
         <entity-xml action="load"
entity-xml-url="component://accounting/testdef/data/AccountingTestsData.xml"/>
     </test-case>

- Can I define a different data source for the test delegator than for
the default delegator?
Because a comment in the entityengine.xml says "Be sure that your
default delegator (or the one you use) uses the same datasource for test."

Yes you can, in one of our configuration we have a specific datasource
for a dedicated postgres database. Default delegator is set to another
datasource.


A second mail will come with our way of integration testing.

Regards,

Gil

Le 21/05/2021 à 14:40, Nicolas Malin a écrit :

> HI both,
>
> Currently I work with Gil for a customer site to different process for
> implement some integration and unit test dedicate to business case.
>
> We will try to share some tips on the following weeks.
>
> Nicolas
>
> On 20/05/2021 20:46, Carsten Schinzer wrote:
>> Hello,
>>
>>
>> definitely I am interested and also would like to work against an aligned
>> standard. For example I found the issue of missing unit tests when
>> refactoring some simple methods to groovy (I promise to finish and submit
>> my started jira tickets in the upcoming Community Days). And I also asked
>> myself the same questions as you do. For the time being I have just guessed
>> where to place them, but yet a better approach would be to document
>> practice with this somewhere and track improvements in Jira.
>>
>> I also would support unit testing from integration testing, which comes
>> along with a definition of unit of course. I prefer the definition of a
>> class method as a unit over the class itself as a unit, but I am open to
>> arguments.
>>
>> My 2 cents.
>> Warm regards
>>
>>
>> Carsten
>>
>> Am Do., 20. Mai 2021 um 15:51 Uhr schrieb Erwin Penner <
>> [hidden email]>:
>>
>>> Hello everybody,
>>>
>>> I would like to create unit and integration tests for my custom modules in
>>> OFBiz.
>>> Unfortunately, information on this subject is sparse.
>>> For this reason, I checked how it is currently solved in the OFBiz modules.
>>> I'll explain what it's about first. At the end of the mail I have some
>>> questions.
>>>
>>> Using the example of the base or common modules in the OFBiz framework,
>>> simple unit tests can be found in a separate test source folder.
>>> src/test/java
>>>
>>> There are also test classes (presumably integration tests) in
>>> base/src/main/java/org/apach /ofbiz/base/test
>>> common/src/main/java/org/apache/ofbiz/common/test
>>>
>>> In the base module there are further test classes in
>>> base/src/main/java/org/apache/ofbiz/base/util/string/test
>>>
>>> So, I thought simple unit tests should be in the separate test source
>>> folder and integration tests under src/main/java/.../test
>>>
>>> Additionally, I found this (old) Confluence entry and was a bit confused:
>>>
>>> https://cwiki.apache.org/confluence/display/OFBIZ/Code+and+test+separation+for+Apache+OFBiz
>>>
>>> My questions are:
>>> - Which test classes belong where?
>>> - Is the current directory structure for tests the final solution or an
>>> incomplete refactoring?
>>> - Could/Should all tests (unit and integration tests) be maintained in
>>> /src/test/?
>>> - Which test classes must be described in the xml-definition under
>>> /testdef ? (My impression so far is that the OFBiz modules only list
>>> classes for integration tests.)
>>> - Should I use the ext-test-reader in my custom ofbiz-component.xml to
>>> load data for integration tests?
>>> - Can I define a different data source for the test delegator than for the
>>> default delegator?
>>> Because a comment in the entityengine.xml says "Be sure that your default
>>> delegator (or the one you use) uses the same datasource for test."
>>>
>>> Thanks in advance! I look forward to your answer/s! :-)
>>>
>>> Erwin
>>>