• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Using ANT to execute JUNIT test cases.

 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I've been playing around with ANT to try and execute several tests in a specific order but have not been able to find out how to do it. Basicly, I am trying to automate the running of a regression/functional test suite for a web application that runs using Selenium. The test suite that i have has the following structure



At the moment each test is run manually so someone has to load the application on teh browser and type everything into the relevant pages. Now i am using Selenium wich will automate this. I would like to use ANT so that i can have a target for each of the above stages. This means i can either run all the tests or i can run a specific Stage. Example Targets will be something like



I have seen several ANT build examples on how to run junit test, for example,



but i still have not seen an example that would run the tests in a specific order. I have written the test cases using Junit 4 and each stage listed above is a test suite.



Each testsuite contains the relevant testcases. Here is an example



Then on the actual test case i would like to use the browser object










If i was to run the above testsuite in ant i will probably do something liek this



1. Given that i am specifying mytests.Stage1TestSuite as the test to run, how do i guarantee that the tests will run in the order they are specified in the test suite?

2. I have thought about not using testsuites and refere to the individual test cases in the ant junit target but this will be overkill as there will be thousands of test cases.

Any hints, tips or suggestions
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tests should be independent, meaning that the order they're run in is not significant.

If you've written your tests in such a way that order is significant, then you're going to either have to specify a lot of stuff manually, I suppose.
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting my reply from your other thread here since it is essentially the same question.

O. Ziggy wrote:if i have 5 test suites in the **/tests/ folder. How will it know which test suite to run first if i run the tests.integration target?


It won't. What's the difference which one gets run first. They are supposed to be independent. If order really does matter, you should rreate a new TestSuite where you run the code in the desired order and have Ant run just that one.
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is the kind of scenario where i would want the test cases to be run a specific order.

Lets say i have a website where you cant do anything without logging on. In this case i have a test case that tests the logging on functionality and then i would have another test case that would test something else. The order they will be executed will matter because i cant test anything before logging on which means the order should be

1. TestLogin
2. TestCreateProduct
3. TestReadProduct

in the above test cases, i cant read any product before it is created and that i have logged and i cant create a product before i have logged on. I have seen a lot of comments about using the setUp() and tearDown() methods but surely that would mean a lot of duplication.

If for example i have to make TestReadProduct test case independent, i would have to put the TestLogin and TestCreateproduct functionality in the setUp() method for the TestCreateProduct test case. Surely this is a maintenance nightmare. Imagine having to maintain 5000 of testcases. I would have to make a lot of changes in a lot of places if the TestLogin functionality changes.


I am thinking of using the "depends" option in ANT.

Something like this

<target=TestReadProduct depends=TestLogin, TestCreateProduct>


isnt there a better way of doing this?

Thanks
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

O. Ziggy wrote:isnt there a better way of doing this?


Yes. Do it in Java. My integration test follows this format:

  • suite wide initialization
  • run all tests
  • suite wide cleanup


  • Seriously, maintaining the dependencies in Ant is coupling the test logic to your current build technology.
     
    O. Ziggy
    Ranch Hand
    Posts: 430
    Android VI Editor Debian
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    Could you elaborate on that please.
    Do you mean use java to run the individual tests and control the execution sequnece of the individual testcases?

    Thanks
     
    Jeanne Boyarsky
    author & internet detective
    Posts: 40035
    809
    Eclipse IDE VI Editor Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    O. Ziggy wrote:Do you mean use java to run the individual tests and control the execution sequnece of the individual testcases?


    Excactly!
     
      Bookmark Topic Watch Topic
    • New Topic