You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Dy...@Sun.COM on 2007/12/04 21:04:57 UTC

JUnit problem

Hi,

I'm trying to create some test cases that only will be run when using
DerbyNetClient. This is what I do:

    private static Test baseSuite(String name) {
        TestSuite suite = new TestSuite(name);

        suite.addTestSuite(StatementJdbc30Test.class);

        if  (usingDerbyNetClient()) {
            // These test CAN be run in embedded mode as well, but
            // they're only meaningful in c/s mode and also take quite
            // a bit of time to run.
            suite.addTest(new StatementJdbc30Test
                          ("xtestMultiExecWithQueryTimeout"));
            suite.addTest(new StatementJdbc30Test
                          ("xtestMaxOpenStatementsWithQueryTimeout"));
        }

        return new CleanDatabaseTestSetup(suite) { 

...

But when I run StatementJdbc30Test I don't see the x-test cases being
run. If comment out  "if  (usingDerbyNetClient()) {" the testcases run just
fine (in both frameworks), so it would seem that the predicate is not
doing what I expect. Does anyone know what I'm missing here?

-- 
dt

Re: JUnit problem

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Dyre.Tjeldvoll@Sun.COM writes:

> Hi,
>
> I'm trying to create some test cases that only will be run when using
> DerbyNetClient. This is what I do:
>
>     private static Test baseSuite(String name) {
>         TestSuite suite = new TestSuite(name);
>
>         suite.addTestSuite(StatementJdbc30Test.class);
>
>         if  (usingDerbyNetClient()) {
>             // These test CAN be run in embedded mode as well, but
>             // they're only meaningful in c/s mode and also take quite
>             // a bit of time to run.
>             suite.addTest(new StatementJdbc30Test
>                           ("xtestMultiExecWithQueryTimeout"));
>             suite.addTest(new StatementJdbc30Test
>                           ("xtestMaxOpenStatementsWithQueryTimeout"));
>         }
>
>         return new CleanDatabaseTestSetup(suite) { 
>
> ...
>
> But when I run StatementJdbc30Test I don't see the x-test cases being
> run. If comment out  "if  (usingDerbyNetClient()) {" the testcases run just
> fine (in both frameworks), so it would seem that the predicate is not
> doing what I expect. Does anyone know what I'm missing here?

usingDerbyNetClient() only works when the test is running. When you're
in the suite() method, you always have the default TestConfiguration.

You could try something like this instead:

    TestSuite clientSuite = new TestSuite(name + " - client only");
    clientSuite.addTest(new StatementJdbc30Test
                        ("xtestMultiExecWithQueryTimeout"));
    clientSuite.addTest(new StatementJdbc30Test
                        ("xtestMaxOpenStatementsWithQueryTimeout"));

    suite.addTest(TestConfiguration.clientServerSuite(clientSuite));

-- 
Knut Anders

Re: JUnit problem

Posted by Dy...@Sun.COM.
Dyre.Tjeldvoll@Sun.COM writes:

> Daniel John Debrunner <dj...@apache.org> writes:
>
>> Does this help:
>>
>> http://wiki.apache.org/db-derby/DerbyJunitTestConfiguration
>>
>> Basically you need to define in the suite method how you want your
>> test fixtures to be run. There is no outside agent at setup time
>> saying it's running in "client" or "embedded" mode.
>>
>> Once a fixture is running, then the usingDerbyNetClient() methods make
>> sense, they indicate a fixture is running in that mode.
>
> Ok, thanks Dan and Knut. I think I understand. The strange thing,
> however, is that I more or less copied this from ProcedureTest.java:
>
>     private static Test baseSuite(String name)
>     {
>         TestSuite suite = new TestSuite(name);
>         
>         // Need JDBC 2 DriverManager to run these tests
>         if (JDBC.vmSupportsJDBC2()) {        	
>         
>         suite.addTestSuite(ProcedureTest.class);
>         if (!usingDerbyNet()) {
>             suite.addTest
>                 (new ProcedureTest
>                  ("xtestExecuteUpdateWithNoDynamicResultSets"));
>             suite.addTest
>                 (new ProcedureTest
>                  ("xtestExecuteUpdateWithNoDynamicResultSets_prepared"));
>             suite.addTest
>                 (new ProcedureTest
>                  ("xtestExecuteUpdateWithOneDynamicResultSet_prepared"));
>
> ...

Actually, I just ran this test and it turns out that this doesn't work
either. The x test cases ARE in fact run in both modes. Hrmpf...

Is there a way of making the usingX predicates throw an exception or
something when they are invoked outside a proper test case? Ideally
there would be a way of rejecting such usage at compile time...

I just tried making them non-static, but that won't work since they
are used in a bunch of static utilities. Oh well, that's life...

-- 
dt

Re: JUnit problem

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Dyre.Tjeldvoll@Sun.COM writes:

> Daniel John Debrunner <dj...@apache.org> writes:
>
>> Does this help:
>>
>> http://wiki.apache.org/db-derby/DerbyJunitTestConfiguration
>>
>> Basically you need to define in the suite method how you want your
>> test fixtures to be run. There is no outside agent at setup time
>> saying it's running in "client" or "embedded" mode.
>>
>> Once a fixture is running, then the usingDerbyNetClient() methods make
>> sense, they indicate a fixture is running in that mode.
>
> Ok, thanks Dan and Knut. I think I understand. The strange thing,
> however, is that I more or less copied this from ProcedureTest.java:

Hi Dyre,

ProcedureTest was written before we had the JUnit framework that we have
today. In the old framework, we started a new process whenever we wanted
to run client/server tests, and set the framework system property to
"DerbyNetClient". Therefore, within a single JUnit run, there would
never be a mix of embedded tests and client/server tests, so checking
the current mode in suite() was OK. This was probably overlooked when
the test was moved from the old JUnit framework to the new framework.

-- 
Knut Anders

Re: JUnit problem

Posted by Dy...@Sun.COM.
Daniel John Debrunner <dj...@apache.org> writes:

> Does this help:
>
> http://wiki.apache.org/db-derby/DerbyJunitTestConfiguration
>
> Basically you need to define in the suite method how you want your
> test fixtures to be run. There is no outside agent at setup time
> saying it's running in "client" or "embedded" mode.
>
> Once a fixture is running, then the usingDerbyNetClient() methods make
> sense, they indicate a fixture is running in that mode.

Ok, thanks Dan and Knut. I think I understand. The strange thing,
however, is that I more or less copied this from ProcedureTest.java:

    private static Test baseSuite(String name)
    {
        TestSuite suite = new TestSuite(name);
        
        // Need JDBC 2 DriverManager to run these tests
        if (JDBC.vmSupportsJDBC2()) {        	
        
        suite.addTestSuite(ProcedureTest.class);
        if (!usingDerbyNet()) {
            suite.addTest
                (new ProcedureTest
                 ("xtestExecuteUpdateWithNoDynamicResultSets"));
            suite.addTest
                (new ProcedureTest
                 ("xtestExecuteUpdateWithNoDynamicResultSets_prepared"));
            suite.addTest
                (new ProcedureTest
                 ("xtestExecuteUpdateWithOneDynamicResultSet_prepared"));

...


-- 
dt

Re: JUnit problem

Posted by Daniel John Debrunner <dj...@apache.org>.
Dyre.Tjeldvoll@Sun.COM wrote:
> Hi,
> 
> I'm trying to create some test cases that only will be run when using
> DerbyNetClient. This is what I do:
> 
>     private static Test baseSuite(String name) {
>         TestSuite suite = new TestSuite(name);
> 
>         suite.addTestSuite(StatementJdbc30Test.class);
> 
>         if  (usingDerbyNetClient()) {
>             // These test CAN be run in embedded mode as well, but
>             // they're only meaningful in c/s mode and also take quite
>             // a bit of time to run.
>             suite.addTest(new StatementJdbc30Test
>                           ("xtestMultiExecWithQueryTimeout"));
>             suite.addTest(new StatementJdbc30Test
>                           ("xtestMaxOpenStatementsWithQueryTimeout"));
>         }
> 
>         return new CleanDatabaseTestSetup(suite) { 
> 
> ...
> 
> But when I run StatementJdbc30Test I don't see the x-test cases being
> run. If comment out  "if  (usingDerbyNetClient()) {" the testcases run just
> fine (in both frameworks), so it would seem that the predicate is not
> doing what I expect. Does anyone know what I'm missing here?
> 

Does this help:

http://wiki.apache.org/db-derby/DerbyJunitTestConfiguration

Basically you need to define in the suite method how you want your test 
fixtures to be run. There is no outside agent at setup time saying it's 
running in "client" or "embedded" mode.

Once a fixture is running, then the usingDerbyNetClient() methods make 
sense, they indicate a fixture is running in that mode.

Dan.