1

When using Selenium where is the data generated for unit testing?

Could it use the same database instance of the project it is working on or new database should be created?

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Hodaut96
  • 93
  • 1
  • 9

2 Answers2

1

Selenium is used to

automates browsers. That's it!

so it is for you to design how the Test framework would handle the data flows. For example, if you decide to go with the Data-driven approach it will allow you to automatically run a test case multiple times with different input and validation values.

Your Selenium code interacts with the SUT's Web UI, so it doesn't really care about what DB is used. However, seleniumhq do recommend going for database-validation when designing your tests. Mainly, records to be retrieved from a database and then later compared against the UI.

It is highly desirable to use sandboxed DB, dedicated entirely for your automation tests. This really depends on how your environments are set up. Using In-memory DB like Hazelcast will speed up things a lot.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
ekostadinov
  • 6,880
  • 3
  • 29
  • 47
0

The other Answer is correct and should be accepted.

As explained there, Selenium automates operation of a web browser in robotic fashion. For other purposes use other tools, alongside Selenium.

Database migration tools

You may be interested to learn about database migration tools such as Flyway or Liquibase that organize your scripts for creating your tables, columns, indexes, and so forth. When encountering a new database or an not-yet-up-to-date database, the tool automatically applies the appropriate scripts to bring that database instance up-to-date.

So this is very helpful with testing. On every test run, you can create a new database, evolve that database structure to the point you wish in your development history, load data, and run your test. Your database is fresh and clean in an expected state, perfect for repeating tests reliably.

You can invoke Flyway in several ways: by Java calls, by command-line console, or by Maven/Gradle/Ant. You can hook this into integration environments like Jenkins. The Flyway Test Extensions project provides further assistance with combining Flyway with testing tools.

See: Integration testing with Flyway (Stack Overflow question)

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154