wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Where to place Selenium tests in separate maven project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Where to place Selenium tests in separate maven project" Watch "Where to place Selenium tests in separate maven project" New topic
Author

Where to place Selenium tests in separate maven project

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Hi Ranchers,

We have a requirement where we need to create a different maven project just to write selenium tests for some other project. Now my question is ideally where should the tests located, in "src/main/java" or in "src/test/java" ? My colleague already committed tests in "test" folder saying we can easily run this tests just by shooting "mvn test" on command prompt.

Though I do not like this approach, I want to keep test in "src/main" folder, because -
1. I like to treat this tests as a production code.
2. What if in future I want to package it as a jar and pass it to some other nightly build server to run tests against my web app?
3. I would like to use "src/main/test" either for writing any test suite around my web tests OR to write any unit tests for web test.

So what would you guys suggest ? Any thoughts?

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

My suggestion is to keep with the standard structure for a maven project (see here).
If you don't use these structures you are:
a) Probably going to have to make some configuration changes to maven in order for it to know where the tests are located because you are not using the usual place. (If you're not forced to make changes then why complicate your maven configuration)
b) Make it harder for anyone used to maven as the folders won't be as you would expect in a maven project

In answer to your question 2, you can have your app deployed to the server during the maven build and then run your tests against it all within maven. You can in maven build a jar with your tests in it so if this would be what you needed you can do it as well.

Sean


I love this place!
Marcin Kwiatkowski
Ranch Hand

Joined: Aug 06, 2007
Posts: 32

Hi!

Using "src/test/java" is not a bad idea. I can't imagine a scenario where you'd have to package them as a jar. If you going to run them on some kind of CI server then you'd probably use maven anyway. Also why would you ever need to write unit tests for selenium tests?

The way I've done it in the past is using something like "src/acceptance-test/java", but that requires some adjustments in your build script and ide.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Sean Clark wrote:My suggestion is to keep with the standard structure for a maven project (see here).

Sean, I'm not changing the standard dir structure. I'm just want to decide where to keep web tests "src/main/java" or "src/test/java"?

Sean Clark wrote:In answer to your question 2, you can have your app deployed to the server during the maven build and then run your tests against it all within maven.

yeah, right; but this looks great if my web tests are in same maven project and not located somewhere in dedicated web test project.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

Sagar Rohankar wrote:Sean, I'm not changing the standard dir structure. I'm just want to decide where to keep web tests "src/main/java" or "src/test/java"?

You're splitting hairs here, you are wanting to use a standard application code folder to store tests, you are changing what that folder does and therefore I think you are changing the standard directory structure. You would need to configure maven not to pick up your web tests otherwise you would end up with them in your WAR file. More effort than it is worth I feel and that is my suggestion. If you wish to take another route then do.
Sagar Rohankar wrote:yeah, right; but this looks great if my web tests are in same maven project and not located somewhere in dedicated web test project.

If you want to include the tests in another project then you could do that through maven by adding a dependency to your main projects test classes jar (you need to configure it to create a jar for the tests.)

I'm not looking to get into a debate, you asked for suggestions and these are mine, if you don't wish to take any notice then you are welcome to.

Sean
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Marcin Kwiatkowski wrote:Also why would you ever need to write unit tests for selenium tests?

Well, just in case I ended up writing selenium pages using page object pattern and if those pages contains some method with some logic. You never know when you're tempted to write unit tests
Marcin Kwiatkowski wrote:The way I've done it in the past is using something like "src/acceptance-test/java", but that requires some adjustments in your build script and ide.

I wish it could be done that way like a separate package "*/integration/*"
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Sean Clark wrote:
Sagar Rohankar wrote:Sean, I'm not changing the standard dir structure. I'm just want to decide where to keep web tests "src/main/java" or "src/test/java"?
You're splitting hairs here, you are wanting to use a standard application code folder to store tests, you are changing what that folder does and therefore I think you are changing the standard directory structure.

Ohh, I thought you saying that I'm changing the dir name. OK. No issues.
Sean Clark wrote:
You would need to configure maven not to pick up your web tests otherwise you would end up with them in your WAR file.

No, It will not, because its a separate jar type project only for web tests.
Sean Clark wrote:
Sagar Rohankar wrote:yeah, right; but this looks great if my web tests are in same maven project and not located somewhere in dedicated web test project.

If you want to include the tests in another project then you could do that through maven by adding a dependency to your main projects test classes jar (you need to configure it to create a jar for the tests.)

That's look like a one great solution, I can certainly add "web test" dependency like this

and my web app project build a war, run a jetty, deploy the war and execute the web tests against it.
Thanks

 
Don't get me started about those stupid light bulbs.
 
subject: Where to place Selenium tests in separate maven project
 
Similar Threads
Importing Maven project in Eclipse?
How to run UT in Eclipse/Maven
Selenium Remote Control
maven - conventions for integration tests
Selenium 2 Best Practice