db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Susan Cline <home4...@pacbell.net>
Subject Re: Integrating a JUnit test into the test harness was: Re: [Db-derby Wiki] Update of "IntroToJUnit" by SusanCline
Date Thu, 31 Aug 2006 00:57:03 GMT
--- Daniel John Debrunner <djd@apache.org> wrote:

> 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();
> >    }
> >   };

Oh, okay, thanks I did not know that.  I removed the wrapper and just have a separate
setup() and suite() method.

> 
> 
> > 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());

I wondered about that, but thought that maybe the goal was to make it more modular,
and not just add individual tests this way.  So now I've done that and removed the 
entry from LangScripts and here is the results of running the tests;

No failures when running my test by itself:

java org.apache.derbyTesting.functionTests.harness.RunTest lang/MathTrigFunctionsTest.junit
*** Start: MathTrigFunctionsTest jdk1.4.2_09 2006-08-30 17:48:42 ***
*** End:   MathTrigFunctionsTest jdk1.4.2_09 2006-08-30 17:49:11 ***

No failures when running the _Suite by itself:

java org.apache.derbyTesting.functionTests.harness.RunTest lang/_Suite.junit
*** Start: _Suite jdk1.4.2_09 2006-08-30 17:49:45 ***
*** End:   _Suite jdk1.4.2_09 2006-08-30 17:50:27 ***

But when I try to run the entire derbylang suite the only test that fails is _Suite,
but I'm wondering if it really failed:

java org.apache.derbyTesting.functionTests.harness.RunSuite derbylang

derbylang_fail.txt:
derbylang/derbylang.fail:lang/_Suite.junit

But derbylang_pass.txt shows this at the bottom of the output:
...
derbylang/derbylang.pass:lang/_Suite.junit
/MathTrigFunctionsTest.pass:lang/MathTrigFunctionsTest.junit

Is there something else I need to do to make sure that RunSuite derbylang reports that _Suite
passes?
> 
> Thanks for trying this stuff out, it shows where I need to add more
> comments etc.

Sure, you're welcome.

> Dan.
> 
> 


Mime
View raw message