Pregunta

I am a developer temporarily tasked with helping the QA team with test automation using JUnit 4 and Selenium WebDriver. I am new to testing and test automation.

Looking at various WebDriver examples, a common pattern is to instantiate an implementation of WebDriver (like FirefoxWebDriver) in the @Before method, use the instance in @Test method to interface with the browser and driver.quit() in @After.

So if there are 5 @Test methods, the browser will be opened, test app initialized and browser closed 5 times.

My question is why open, initialize and close required for each test case? My guess is to prevent one test case failure from having a negative side effect on other tests. Is this correct? Are there any other reasons?

¿Fue útil?

Solución

Great Question!

Coming from the OTHER side, i'm a QA automation test engineer, working with the Dev team on automation...

As @Prateek and myself have pointed out, there are a couple reasons why.

The two most obvious:

  1. The main purpose of testing is to localize the error. If all the tests would run in one go and it fails, you would be unable to tell where it failed. ~Prateek

  2. Multithreading is a reason why as well. Picture your company having thousands of regression tests that need to be ran. Having each test isolated, makes it so they are completely independent of other tests, making you able to potentionally run them all at the same time (assuming your app can handle it) which .. say each test takes 1 minute to run, 1x1000=1000 minutes to run each test sequentially as opposed to finishing them all in just 1 minute!

So you are correct in your assumtion here -

My guess is to prevent one test case failure from having a negative side effect on other tests. Is this correct?

But of course, there are more reasons than that alone.

Otros consejos

There is one more reason, each time WebDriver is instantiated, a new profile is created which clears browser cache..Currently there is no other way to clear browser cache..

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top