cancel
Showing results for 
Search instead for 
Did you mean: 

Executing all @UnitTests in testsrc/ and in web/testsrc in one ant run

Former Member

Hi,

I'm trying to execute all the @UnitTests in testsrc/ and web/testsrc/ of our extensions in one ant build on our CI server. If I execute

 ant yunitinit unittests 

only the tests in testsrc/ are executed. Calling

 ant unittests -Dtestclasses.web=true

executes only the tests in web/testsrc/ but not the ones in testsrc/.

Any suggestions? Is it possible to execute all the tests at once? My hybris Platform version is 5.1.1.0.

Thanks for your help,

Olaf

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Have a look at this answer: https://answers.sap.com/questions/12751500/executing-unit-tests-in-hybris-5.html?childToView=1277668...

Another solution is to create your own ant script having something like this:

     <target name="run-tests">
         <fail message="'testtarget' is a mandatory parameter!" unless="testtarget" />
         <fail message="'web' is a mandatory parameter!" unless="web" />
  
         <echo message="Starting '${testtarget}' for the following extensions: '${test.extension.names}'; web='${web}'." />
     
         <property name="hybris.platform.basedir" location="./../../bin/platform/" />
         <property name="hybris.ant.antfile" value="build.xml" />
         
         <property name="testresult.output.file" location="${hybris.platform.basedir}/../../log/junit/TESTS-TestSuites.xml" />
         <dirname property="testresult.output.directory" file="${testresult.output.file}"/>
 
         <ant antfile="${hybris.ant.antfile}" dir="${hybris.platform.basedir}" target="${testtarget}">
             <property name="testclasses.extensions" value="${test.extension.names}" />
             <property name="testclasses.web" value="${web}" />
         </ant>
         
         <!--
             Since we're calling hybris' internal yunit target twice the second call would overwrite the
             results (${testresult.output.file}) from the first run. Thus we simply move the file from the
             first run to make sure Jenkins can collect ALL results.
         -->
         <move file="${testresult.output.file}" tofile="${testresult.output.directory}/TESTS-${testtarget}-${web}.xml" />
     </target>
 
     
     <target name="run-continuously-tests">
         <antcall target="run-tests">
             <param name="testtarget" value="unittests" />
             <param name="web" value="false" />
         </antcall>
         
         <antcall target="run-tests">
             <param name="testtarget" value="unittests" />
             <param name="web" value="true" />
         </antcall>
     </target>
 

Of course you have to change the paths and parameters accordingly to your setup

Former Member
0 Kudos

What is the hybris suggestion regarding ant script extensions? Any supported approach?

Former Member
0 Kudos

There was a time (around 4.7), a

 yunitinit yunit yunitweb

would do the job. Maybe it is still working.

Former Member
0 Kudos

Yes, we used this for the old hybris 4.7. build. But IIRC they are deprecated with 5.1 and they execute much slower.

Former Member
0 Kudos

Perhaps you could make your own ant target? Just place this code in one of the buildcallbacks.xml files (possibly in your *core extension). Try this:

     <target name="citests" description="executes all required tests for the CI Pipeline">
         <callback extname="" target="before_citests"/>
         <annotationtests annotations="integrationtests,unittests"/>
         <annotationtests annotations="unittests"  web="true"/>
         <callback extname="" target="after_citests"/>
     </target>

If that doesn't work for you, then perhaps you will have to consider further customisation: https://wiki.hybris.com/display/release5/Customizing+Tests+Execution

Former Member
0 Kudos

Hi Scott,

thank you for your help! Unfortunately the parameter "web" is mapped to an (unmodifiable) property in the annotationtests macro and thus the second call executes the non-web tests, too.

I tried wrapping it in an antcall that executed both tests but the web test result overwrote the non-web test result 😞

So I'll try the Customization...