You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Marco Mistroni <mm...@gmail.com> on 2008/04/26 19:22:03 UTC

Mvn2/Selenium/CArgo/JUnit problem

hi all,
 i am running my UAT tests in mvn2 using Cargo and selenium .
Due to problems using cargo plugin (when it started it was not able to find
some jars for my webapp), i have written a base test
which starts cargo and selenium.
Problem i have now is that cargo starts/stops at every setUP and tearDown.
Even though tests are ran automatically, i am  trying to use a mechanism
so tha cargo is started only once and it is stopped only once during hwole
lifecycle of my tests.

Wiuth JUnit3, i am unable to find  a method that gets called only once (sort
of SetUpFixture) for the whole junit session...

anyone could give help hee?

here' smy AbstractSeleniumTest  for reference

public abstract class AbstractSeleniumTest extends SeleneseTestCase {
    protected DefaultSelenium selenium;
    private  Logger log = Logger.getLogger(this.getClass());
    private InstalledLocalContainer container;

    public void setUp() throws Exception {
        System.err.println("--SettingUp Fixture....");
        startCargo();
        selenium = createSeleniumClient("http://localhost:8080/");
        selenium.start();
    }



    public void tearDown() throws Exception {
        stopCargo();
        selenium.stop();

    }

    protected DefaultSelenium createSeleniumClient(String url) throws
Exception {
        return new DefaultSelenium("localhost", 4444, "*firefox", url);
    }

    private void startCargo() throws Exception {
        // (1) Optional step to install the container from a URL pointing to
its distribution
        System.err.println("--- Starting cargo.. ......");
        Installer installer = new ZipURLInstaller(
            new URL("
http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.zip
"));
        installer.install();

        // (2) Create the Cargo Container instance wrapping our physical
container
        LocalConfiguration configuration =
            (LocalConfiguration) new
DefaultConfigurationFactory().createConfiguration(
            "tomcat5x", ContainerType.INSTALLED,
ConfigurationType.STANDALONE);
        container =
            (InstalledLocalContainer) new
DefaultContainerFactory().createContainer(
                "tomcat5x", ContainerType.INSTALLED, configuration);
        container.setHome(installer.getHome());

        // (3) Statically deploy some WAR (optional)
        configuration.addDeployable(new WAR("target/BudgetWeb.war"));

        // (4) Start the container
        container.start();
    }

    private void stopCargo() throws Exception {
        container.stop();
    }

thanks and regards
  Marco

Re: Mvn2/Selenium/CArgo/JUnit problem

Posted by Dan Tran <da...@gmail.com>.
lump all you test cases into one test suit, and then have your test
suite's setup/teardown to start/stop tomcat respectively.

I think the Struts 2 integration test does this. check it out.

-D

On Sat, Apr 26, 2008 at 10:22 AM, Marco Mistroni <mm...@gmail.com> wrote:
> hi all,
>  i am running my UAT tests in mvn2 using Cargo and selenium .
> Due to problems using cargo plugin (when it started it was not able to find
> some jars for my webapp), i have written a base test
> which starts cargo and selenium.
> Problem i have now is that cargo starts/stops at every setUP and tearDown.
> Even though tests are ran automatically, i am  trying to use a mechanism
> so tha cargo is started only once and it is stopped only once during hwole
> lifecycle of my tests.
>
> Wiuth JUnit3, i am unable to find  a method that gets called only once (sort
> of SetUpFixture) for the whole junit session...
>
> anyone could give help hee?
>
> here' smy AbstractSeleniumTest  for reference
>
> public abstract class AbstractSeleniumTest extends SeleneseTestCase {
>    protected DefaultSelenium selenium;
>    private  Logger log = Logger.getLogger(this.getClass());
>    private InstalledLocalContainer container;
>
>    public void setUp() throws Exception {
>        System.err.println("--SettingUp Fixture....");
>        startCargo();
>        selenium = createSeleniumClient("http://localhost:8080/");
>        selenium.start();
>    }
>
>
>
>    public void tearDown() throws Exception {
>        stopCargo();
>        selenium.stop();
>
>    }
>
>    protected DefaultSelenium createSeleniumClient(String url) throws
> Exception {
>        return new DefaultSelenium("localhost", 4444, "*firefox", url);
>    }
>
>    private void startCargo() throws Exception {
>        // (1) Optional step to install the container from a URL pointing to
> its distribution
>        System.err.println("--- Starting cargo.. ......");
>        Installer installer = new ZipURLInstaller(
>            new URL("
> http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.zip
> "));
>        installer.install();
>
>        // (2) Create the Cargo Container instance wrapping our physical
> container
>        LocalConfiguration configuration =
>            (LocalConfiguration) new
> DefaultConfigurationFactory().createConfiguration(
>            "tomcat5x", ContainerType.INSTALLED,
> ConfigurationType.STANDALONE);
>        container =
>            (InstalledLocalContainer) new
> DefaultContainerFactory().createContainer(
>                "tomcat5x", ContainerType.INSTALLED, configuration);
>        container.setHome(installer.getHome());
>
>        // (3) Statically deploy some WAR (optional)
>        configuration.addDeployable(new WAR("target/BudgetWeb.war"));
>
>        // (4) Start the container
>        container.start();
>    }
>
>    private void stopCargo() throws Exception {
>        container.stop();
>    }
>
> thanks and regards
>  Marco
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Mvn2/Selenium/CArgo/JUnit problem

Posted by Wendy Smoak <ws...@gmail.com>.
On Sun, Apr 27, 2008 at 1:22 AM, Marco Mistroni <mm...@gmail.com> wrote:

>  Problem i have now is that cargo starts/stops at every setUP and tearDown.
>  Even though tests are ran automatically, i am  trying to use a mechanism
>  so tha cargo is started only once and it is stopped only once during hwole
>  lifecycle of my tests.

There is a JUnit TestSetup class in the Shale test framework that will
help with this (and I'm sure it's described on the Cargo website...)

http://shale.apache.org/shale-test/apidocs/org/apache/shale/test/cargo/CargoTestSetup.html

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Mvn2/Selenium/CArgo/JUnit problem

Posted by Kalle Korhonen <ka...@gmail.com>.
Pom-based is pretty simple and we are using Tomcat in that case:
http://svn.trails.codehaus.org/browse/~raw,r=844/trails/trunk/trails/examples/simple/pom.xml.
Setting up the container in abstract base test class doesn't have much to do
with Maven, but the advantage is that you can run everything in-process and
from your IDE.

Kalle


On Sat, Apr 26, 2008 at 1:33 PM, Marco Mistroni <mm...@gmail.com> wrote:

> Kalle,
>  i have started up cargo in my own test coz when i deployed my .war using
> jetty,
> it was always complaining on missing jar files (all related to my war
> application)
>
> i did a research and found that there was a bug in jetty 'embedded
> container' as it
> was not able to load certain classes from classpath
> this happened when i started to use selenium tests about 5 months ago
>
> i'll appreciate if you can share ur pom.xml, as my original idea was to
> use
> jetty too....
>
> thanks and regards
>  marco
>
> On Sat, Apr 26, 2008 at 8:43 PM, Kalle Korhonen <
> kalle.o.korhonen@gmail.com>
> wrote:
>
> > An interesting approach. In my container-based integration testing, I've
> > either configured all in the pom and used the maven cargo plugin to
> start
> > up
> > the container in pre-integration-test phase, then stop it in
> > post-integration-test, or when I've wanted to do everything in-process
> and
> > in-code, I've created a JUnit base test class and held a Jetty instance
> in
> > a
> > static property (so it survives through repeated setUp/tearDowns). I
> don't
> > see what using Cargo buys you if you are setting up everything in code.
> >
> > Kalle
> >
> >
> > On Sat, Apr 26, 2008 at 10:22 AM, Marco Mistroni <mm...@gmail.com>
> > wrote:
> >
> > > hi all,
> > >  i am running my UAT tests in mvn2 using Cargo and selenium .
> > > Due to problems using cargo plugin (when it started it was not able to
> > > find
> > > some jars for my webapp), i have written a base test
> > > which starts cargo and selenium.
> > > Problem i have now is that cargo starts/stops at every setUP and
> > tearDown.
> > > Even though tests are ran automatically, i am  trying to use a
> mechanism
> > > so tha cargo is started only once and it is stopped only once during
> > hwole
> > > lifecycle of my tests.
> > >
> > > Wiuth JUnit3, i am unable to find  a method that gets called only once
> > > (sort
> > > of SetUpFixture) for the whole junit session...
> > >
> > > anyone could give help hee?
> > >
> > > here' smy AbstractSeleniumTest  for reference
> > >
> > > public abstract class AbstractSeleniumTest extends SeleneseTestCase {
> > >    protected DefaultSelenium selenium;
> > >    private  Logger log = Logger.getLogger(this.getClass());
> > >    private InstalledLocalContainer container;
> > >
> > >    public void setUp() throws Exception {
> > >        System.err.println("--SettingUp Fixture....");
> > >        startCargo();
> > >        selenium = createSeleniumClient("http://localhost:8080/");
> > >        selenium.start();
> > >    }
> > >
> > >
> > >
> > >    public void tearDown() throws Exception {
> > >        stopCargo();
> > >        selenium.stop();
> > >
> > >    }
> > >
> > >    protected DefaultSelenium createSeleniumClient(String url) throws
> > > Exception {
> > >        return new DefaultSelenium("localhost", 4444, "*firefox", url);
> > >    }
> > >
> > >    private void startCargo() throws Exception {
> > >        // (1) Optional step to install the container from a URL
> pointing
> > > to
> > > its distribution
> > >        System.err.println("--- Starting cargo.. ......");
> > >        Installer installer = new ZipURLInstaller(
> > >            new URL("
> > >
> > >
> >
> http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.zip
> > > "));
> > >        installer.install();
> > >
> > >        // (2) Create the Cargo Container instance wrapping our
> physical
> > > container
> > >        LocalConfiguration configuration =
> > >            (LocalConfiguration) new
> > > DefaultConfigurationFactory().createConfiguration(
> > >            "tomcat5x", ContainerType.INSTALLED,
> > > ConfigurationType.STANDALONE);
> > >        container =
> > >            (InstalledLocalContainer) new
> > > DefaultContainerFactory().createContainer(
> > >                "tomcat5x", ContainerType.INSTALLED, configuration);
> > >        container.setHome(installer.getHome());
> > >
> > >        // (3) Statically deploy some WAR (optional)
> > >        configuration.addDeployable(new WAR("target/BudgetWeb.war"));
> > >
> > >        // (4) Start the container
> > >        container.start();
> > >    }
> > >
> > >    private void stopCargo() throws Exception {
> > >        container.stop();
> > >    }
> > >
> > > thanks and regards
> > >   Marco
> > >
> >
>

Re: Mvn2/Selenium/CArgo/JUnit problem

Posted by Marco Mistroni <mm...@gmail.com>.
Kalle,
 i have started up cargo in my own test coz when i deployed my .war using
jetty,
it was always complaining on missing jar files (all related to my war
application)

i did a research and found that there was a bug in jetty 'embedded
container' as it
was not able to load certain classes from classpath
this happened when i started to use selenium tests about 5 months ago

i'll appreciate if you can share ur pom.xml, as my original idea was to use
jetty too....

thanks and regards
 marco

On Sat, Apr 26, 2008 at 8:43 PM, Kalle Korhonen <ka...@gmail.com>
wrote:

> An interesting approach. In my container-based integration testing, I've
> either configured all in the pom and used the maven cargo plugin to start
> up
> the container in pre-integration-test phase, then stop it in
> post-integration-test, or when I've wanted to do everything in-process and
> in-code, I've created a JUnit base test class and held a Jetty instance in
> a
> static property (so it survives through repeated setUp/tearDowns). I don't
> see what using Cargo buys you if you are setting up everything in code.
>
> Kalle
>
>
> On Sat, Apr 26, 2008 at 10:22 AM, Marco Mistroni <mm...@gmail.com>
> wrote:
>
> > hi all,
> >  i am running my UAT tests in mvn2 using Cargo and selenium .
> > Due to problems using cargo plugin (when it started it was not able to
> > find
> > some jars for my webapp), i have written a base test
> > which starts cargo and selenium.
> > Problem i have now is that cargo starts/stops at every setUP and
> tearDown.
> > Even though tests are ran automatically, i am  trying to use a mechanism
> > so tha cargo is started only once and it is stopped only once during
> hwole
> > lifecycle of my tests.
> >
> > Wiuth JUnit3, i am unable to find  a method that gets called only once
> > (sort
> > of SetUpFixture) for the whole junit session...
> >
> > anyone could give help hee?
> >
> > here' smy AbstractSeleniumTest  for reference
> >
> > public abstract class AbstractSeleniumTest extends SeleneseTestCase {
> >    protected DefaultSelenium selenium;
> >    private  Logger log = Logger.getLogger(this.getClass());
> >    private InstalledLocalContainer container;
> >
> >    public void setUp() throws Exception {
> >        System.err.println("--SettingUp Fixture....");
> >        startCargo();
> >        selenium = createSeleniumClient("http://localhost:8080/");
> >        selenium.start();
> >    }
> >
> >
> >
> >    public void tearDown() throws Exception {
> >        stopCargo();
> >        selenium.stop();
> >
> >    }
> >
> >    protected DefaultSelenium createSeleniumClient(String url) throws
> > Exception {
> >        return new DefaultSelenium("localhost", 4444, "*firefox", url);
> >    }
> >
> >    private void startCargo() throws Exception {
> >        // (1) Optional step to install the container from a URL pointing
> > to
> > its distribution
> >        System.err.println("--- Starting cargo.. ......");
> >        Installer installer = new ZipURLInstaller(
> >            new URL("
> >
> >
> http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.zip
> > "));
> >        installer.install();
> >
> >        // (2) Create the Cargo Container instance wrapping our physical
> > container
> >        LocalConfiguration configuration =
> >            (LocalConfiguration) new
> > DefaultConfigurationFactory().createConfiguration(
> >            "tomcat5x", ContainerType.INSTALLED,
> > ConfigurationType.STANDALONE);
> >        container =
> >            (InstalledLocalContainer) new
> > DefaultContainerFactory().createContainer(
> >                "tomcat5x", ContainerType.INSTALLED, configuration);
> >        container.setHome(installer.getHome());
> >
> >        // (3) Statically deploy some WAR (optional)
> >        configuration.addDeployable(new WAR("target/BudgetWeb.war"));
> >
> >        // (4) Start the container
> >        container.start();
> >    }
> >
> >    private void stopCargo() throws Exception {
> >        container.stop();
> >    }
> >
> > thanks and regards
> >   Marco
> >
>

Re: Mvn2/Selenium/CArgo/JUnit problem

Posted by Kalle Korhonen <ka...@gmail.com>.
An interesting approach. In my container-based integration testing, I've
either configured all in the pom and used the maven cargo plugin to start up
the container in pre-integration-test phase, then stop it in
post-integration-test, or when I've wanted to do everything in-process and
in-code, I've created a JUnit base test class and held a Jetty instance in a
static property (so it survives through repeated setUp/tearDowns). I don't
see what using Cargo buys you if you are setting up everything in code.

Kalle


On Sat, Apr 26, 2008 at 10:22 AM, Marco Mistroni <mm...@gmail.com>
wrote:

> hi all,
>  i am running my UAT tests in mvn2 using Cargo and selenium .
> Due to problems using cargo plugin (when it started it was not able to
> find
> some jars for my webapp), i have written a base test
> which starts cargo and selenium.
> Problem i have now is that cargo starts/stops at every setUP and tearDown.
> Even though tests are ran automatically, i am  trying to use a mechanism
> so tha cargo is started only once and it is stopped only once during hwole
> lifecycle of my tests.
>
> Wiuth JUnit3, i am unable to find  a method that gets called only once
> (sort
> of SetUpFixture) for the whole junit session...
>
> anyone could give help hee?
>
> here' smy AbstractSeleniumTest  for reference
>
> public abstract class AbstractSeleniumTest extends SeleneseTestCase {
>    protected DefaultSelenium selenium;
>    private  Logger log = Logger.getLogger(this.getClass());
>    private InstalledLocalContainer container;
>
>    public void setUp() throws Exception {
>        System.err.println("--SettingUp Fixture....");
>        startCargo();
>        selenium = createSeleniumClient("http://localhost:8080/");
>        selenium.start();
>    }
>
>
>
>    public void tearDown() throws Exception {
>        stopCargo();
>        selenium.stop();
>
>    }
>
>    protected DefaultSelenium createSeleniumClient(String url) throws
> Exception {
>        return new DefaultSelenium("localhost", 4444, "*firefox", url);
>    }
>
>    private void startCargo() throws Exception {
>        // (1) Optional step to install the container from a URL pointing
> to
> its distribution
>        System.err.println("--- Starting cargo.. ......");
>        Installer installer = new ZipURLInstaller(
>            new URL("
>
> http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.zip
> "));
>        installer.install();
>
>        // (2) Create the Cargo Container instance wrapping our physical
> container
>        LocalConfiguration configuration =
>            (LocalConfiguration) new
> DefaultConfigurationFactory().createConfiguration(
>            "tomcat5x", ContainerType.INSTALLED,
> ConfigurationType.STANDALONE);
>        container =
>            (InstalledLocalContainer) new
> DefaultContainerFactory().createContainer(
>                "tomcat5x", ContainerType.INSTALLED, configuration);
>        container.setHome(installer.getHome());
>
>        // (3) Statically deploy some WAR (optional)
>        configuration.addDeployable(new WAR("target/BudgetWeb.war"));
>
>        // (4) Start the container
>        container.start();
>    }
>
>    private void stopCargo() throws Exception {
>        container.stop();
>    }
>
> thanks and regards
>   Marco
>