3

I'm working on a Java application, it's a middleware between two ticketing webapps. I want to write end2end tests using Selenium to test functionality.

Let's say my testing process goes like this: I manually start a Jenkins Job, it compiles my app using maven, launches unit tests, then if the unit tests pass, deploys the app on the test server. I used to manually test each feature from this point which consist of going in the first ticketing web application, filling some forms, then checking and verifying expected behaviour in the second webapp based on my manual tests my first application.

Now I want to let Selenium-Webdriver do the form filling and checking (not by using Selenium-RC or Selenium-IDE, but really writing java code with the Webdriver)

But where should it go?

  • I've seen tutorials putting end2end tests in JUnit tests, but first, it doesn't really make sense to put them in unit test, second, I would need my app to be deployed to test it. Would it make sense to start all (or just some) unit test to start end2end tests?
  • Other tutorials put the tests in a int main void() function and executing them on their IDE, but I guess it's just for quick demonstration of the WebDriver.
  • I've been thinking if I should do a separate Maven project, put all the (Selenium) tests in there, then somehow start it after Jenkins has deployed.

Is there some kind of recommendations on how to do that? Something like where should be Selenium on a CI chain and in the code ?

I've tried to Google it, but I only found tutorials about how to set and use Selenium.

Asoub
  • 133
  • 5
  • 1
    What I have done before for a C# project with Jenkins that had unit tests and end-to-end tests was to separate the two type of tests in different modules (both types of tests were written using the equivalent of junit) and then execute the unit tests before deployment and the end-to-end tests after. – DobromirM Apr 05 '19 at 15:13
  • You might want to check Maven's Surefire and Failsafe plugins: https://michaelrice.com/2014/04/maven-surefire-failsafe-the-easiest-way/ – DobromirM Apr 05 '19 at 15:20

1 Answers1

4

What I will typically do is keep all of my tests under the test directory. I separate them by creating two modules: integration-tests and unit-tests.

Example project structure:

MyAwesomeProject
    ├───main
    │   └───java
    └───test
        └───java
            ├───integration-tests
            └───unit-tests

The standard convention is to use *Test.java for unit tests and *IT.java for integration tests.

You can then use Maven's Surefire plugin to run the unit-tests and Failsafe plugin to run the integration tests.

DobromirM
  • 232
  • 2
  • 8
  • 1
    Thank you ! never heard of the *IT.java convention, and I'll check the plugins. As the integrations tests are in the project, if I have multiple projects, and End2End tests cover all of them, I guess I should do that in the core project ? I'll wait a little before validating your answer. – Asoub Apr 06 '19 at 19:58
  • 2
    Possibly consider adding in ui-tests as integration tests may not require the UI. – lloyd Apr 08 '19 at 06:40