db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@apache.org>
Subject Re: Integrating a JUnit test into the test harness was: Re: [Db-derby Wiki] Update of "IntroToJUnit" by SusanCline
Date Wed, 30 Aug 2006 23:09:22 GMT
home4slc@pacbell.net wrote:

> As Dan mentioned below my example about integrating a JUnit test into the Derby test
harness
> was not accurate.  I've changed the wiki page IntroToJUnit to point to the other JUnit
wiki
> pages which are more relevant to Derby for information about this.
>  
> However, I've spent some time trying to get my JUnit test that runs fine in stand-alone
mode
> to be integrated into the test harness.  
>  
> To be clear what I mean about stand-alone mode, I am successful with these two invocations
> of the MathTrigFunctionsTest JUnit class:
>  
> C:\derby_src\development_branch\trunk>java junit.textui.TestRunner org.apache.de
> rbyTesting.functionTests.tests.lang.MathTrigFunctionsTest
> ................
> Time: 21.231
> OK (16 tests)
>  
> C:\derby_src\development_branch\trunk>java org.apache.derbyTesting.functionTests
> .harness.RunTest lang/MathTrigFunctionsTest.junit
> *** Start: MathTrigFunctionsTest jdk1.4.2_09 2006-08-30 14:24:08 ***
> *** End:   MathTrigFunctionsTest jdk1.4.2_09 2006-08-30 14:24:48 ***
>  
> I'm not sure if I have enough time to get this working, or if someone else can help.
 Here's what I've 
> done so far, maybe someone has an idea of what needs to be done to get this to work.
>  
> 1) Created a class that extends the BaseJDBCTestCase class, which is in the 
>     org.apache.derbyTesting.functionTests.tests.lang package.
>     (I've removed the private Connection variable per Dan's suggestion below.)
>  
> 2) I created a suite() method shown below:
>  
>  public static Test suite() {
>   TestSuite suite = new TestSuite();
>   suite.addTestSuite(MathTrigFunctionsTest.class);
>   TestSetup wrapper = new BaseJDBCTestSetup(suite) {
>    public void setUp() throws Exception {
>         // initialize variables
>    }
>    protected void tearDown() throws Exception {
>     super.tearDown();
>    }
>   };
>   return wrapper;
>  }

You don't need to have the wrapper, I think what you have defined there
is a new decorator class that does nothing.

BaseJDBCTestSetup is an abstract TestSetup class or decorator that can
be used to build a concrete decorator that uses a JDBC connection.
Decorators are used to wrap logic (setUp and tearDown) around a set or
suite of tests. For example if all the cases (fixtures) in your test
case used a fixed schema that could be created once, you would create it
in a test decorator setUp and remove it in the tearDown, something like

>   TestSetup wrapper = new BaseJDBCTestSetup(suite) {
>    public void setUp() throws Exception {
>         Statement s = getConnection().createStatement();
          s.execute("CREATE TABLE ...");
          s.execute("CREATE INDEX ...");
          ...
          s.close();
>    }
>    protected void tearDown() throws Exception {
>         Statement s = getConnection().createStatement();
          s.execute("DROPTABLE ...");
          ...
          s.close();
>     super.tearDown();
>    }
>   };


> 3) I looked at the _Suite.java file in the lang package.  From what I can tell this adds
the
> suites from LangScripts class' suite.

It is meant to run all JUnit tests in the lang package, the LangScripts
is one such test, others have yet to be added because they might need
additional functionality.

>  
> 4) Looking at the LangScripts class it runs only SQL tests.  Just for kicks I added my
JUnit
> test class name to the LangScripts tests to be run to see what would happen;
>  
>  private static final String[] SQL_LANGUAGE_TESTS = {
>   "case",
>   "constantExpression",
>   "MathTrigFunctionsTest"
>   }; 

LangScripts is a Junit test class that runs SQL scripts in the lang
package, the array of names in SQL_LANGUAGE_TESTS are names of .sql
files. It's not a general holder for langauge JUnit tests.


> *** End:   _Suite jdk1.4.2_09 derbylang:derbylang 2006-08-30 15:14:57 ***
>  
> Does anyone know what I have to do to get my MathTrigFunctionsTest to run as part of
the
> test harness using the _Suite class?

Add a line like this to the tests.lang._Suite.suite() method

  suite.addTest(MathTrigFunctionsTest.suite());

Thanks for trying this stuff out, it shows where I need to add more
comments etc.
Dan.


Mime
View raw message