Showing posts with label unittest. Show all posts
Showing posts with label unittest. Show all posts

Friday, April 6, 2018

Spring testing

spring-test

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html

spring-boot-test

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

@ContextConfiguration(locations = "/test-db-context.xml")

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.pierre.sourcing.dao, com.pierre.xcoll.dao" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@pippo:1521:PLUTO" />
        <property name="username" value="pippouser" />
        <property name="password" value="pippopassword" />
    </bean>

    <bean id="transManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
        <property name="dataSource" ref="dataSource" />
    </bean>

    <context:component-scan base-package="com.pierre.sourcing.dao" />
</beans>



Important annotations

org.springframework.test.annotation.Rollback; indicates whether the transaction for a transactional test method should be rolled back after the test method has completed.

org.springframework.transaction.annotation.Transactional

org.springframework.test.context.ContextConfiguration @ContextConfiguration("/test-config.xml") declares the application context resource locations or the annotated classes that will be used to load the context.

org.springframework.test.context.jdbc.Sql at class level, like in @Sql(scripts = "/preparation-sqls/cleanup-test-data.sql") , to run SQL BEFORE the test execution

org.springframework.test.context.junit4.SpringRunner (@RunWith(SpringRunner.class) )

org.springframework.beans.factory.annotation.Autowired



Wednesday, March 25, 2015

Poor man's unittests in WLST

Python comes with a very elaborate unittest module , and there is no reason NOT to use it, unless a) you are bound to a VERY old implementation of Python B) you are lazy and stupid like me

The good news is that it's really easy to implement a "poor man's" version of a unittest:

totalErrors = 0
totalTests = 0

def assertTrue(booleanCondition, message):
  global totalTests, totalErrors
  totalTests = totalTests + 1
  if (not booleanCondition):
    print "ERROR:", message
    totalErrors = totalErrors + 1



#your testing code here

assertTrue(domain is not None, "domain is not None")


#print test summary

print ""
print "totalTests=", totalTests
if (totalErrors == 0):
  print 'SUCCESS'
else:
  print 'FAILURE, totalErrors=', totalErrors
  





One big step forward it to use the inspect module to print the actual assertTrue statement being executed - so you avoid having to pass also the message:

import inspect

totalErrors = 0
totalTests = 0

def assertTrue(booleanCondition, message):
  global totalTests, totalErrors
  totalTests = totalTests + 1
  if (not booleanCondition):
    frame,filename,line_number,function_name,lines,index = inspect.stack()[1]
    print "ERROR:", message, frame,filename,line_number,function_name,lines,index
    totalErrors = totalErrors + 1



#your testing code here

assertTrue(domain is not None)


#print test summary

print ""
print "totalTests=", totalTests
if (totalErrors == 0):
  print 'SUCCESS'
else:
  print 'FAILURE, totalErrors=', totalErrors
  





I love being minimalistic and lazy....

Wednesday, May 5, 2010

XQuery and Unit Tests

XQuery can turn into a nightmare, not much during development, but during their maintenance.... XQuery code is very convoluted (XPath expressions can be daunting) and after one week you have coded them I dare you understand what you wrote in the first place. You touch it, you break it.

Hence it's paramount to unit test them. I am looking at the best way of doing it either INSIDE OSB or INSIDE ECLIPSE.

One way could be to follow this approach - INSIDE OSB:

http://blogs.oracle.com/knutvatsendvik/2010/03/unit_testing_framework_for_xquery.html

The utility is very well thought, especially impressive if the XMLDiffXQ utility

As for invoking directly XQuery from Java, here are the xquery related jars in OSB:



   ¦  C:\bea103osb\modules\                                                                                       ¦
   ¦   22-04-10 13:52¦        54443¦   A      ¦com.bea.core.xquery.beaxmlbeans-interop_1.2.1.0.jar                ¦
   ¦   22-04-10 13:52¦        55472¦   A      ¦com.bea.core.xquery.xmlbeans-interop_1.2.1.0.jar                   ¦
   ¦   22-04-10 13:52¦      4563307¦   A      ¦com.bea.core.xquery_1.2.1.0.jar                                    ¦
   ¦ ------------------------------------------------------------------------------------------------------------ ¦
   ¦  C:\bea103osb\modules\features\                                                                              ¦
   ¦   22-04-10 13:52¦          517¦   A      ¦weblogic.server.modules.xquery_10.3.0.0.jar                        ¦
   ¦ ------------------------------------------------------------------------------------------------------------ ¦
   ¦  C:\bea103osb\osb_10.3\eclipse\plugins\com.bea.alsb.xquery.xmlbeans-interop_1.0.200\lib\                     ¦
   ¦   22-04-10 14:22¦        54443¦   A      ¦com.bea.core.xquery.beaxmlbeans-interop_1.2.1.0.jar                ¦
   ¦   22-04-10 14:22¦        55472¦   A      ¦com.bea.core.xquery.xmlbeans-interop_1.2.1.0.jar                   ¦
   ¦ ------------------------------------------------------------------------------------------------------------ ¦
   ¦  C:\bea103osb\osb_10.3\eclipse\plugins\com.bea.alsb.xquery_1.0.200\lib\                                      ¦
   ¦   22-04-10 14:22¦      4563307¦   A      ¦com.bea.core.xquery_1.2.1.0.jar                                    ¦
   ¦ ------------------------------------------------------------------------------------------------------------ ¦
   ¦  C:\bea103osb\tools\eclipse_pkgs\2.0\pkgs\eclipse\plugins\com.bea.wli.ide.xquery.core_10.3.0\                ¦
   ¦   22-04-10 14:05¦       150403¦   A      ¦xquery-core.jar                                                    ¦
   ¦ ------------------------------------------------------------------------------------------------------------ ¦
   ¦  C:\bea103osb\tools\eclipse_pkgs\2.0\pkgs\eclipse\plugins\com.bea.wli.ide.xquery.ui_10.3.0\                  ¦
   ¦   22-04-10 14:05¦       148611¦   A      ¦xquery-ui.jar                                                      ¦

Here http://biemond.blogspot.com/2008/11/using-xquery-in-jdeveloper-11g-and.html is an example of how to execute XQuery code from Java... but it requires JDeveloper!

Here http://wordpress.transentia.com.au/wordpress/2010/11/20/unit-testing-xquery-using-osbs-api-2/  is someone who seems to have drunk the bitter cup to its last sip and managed to implement Unit Testing for OSB Xqueries..... Kudos!