开发者

Selenium Unit Test using JUnit (Java)

I just want to quickly ask, I found all over the internet and even here on SO, how Selenium IDE can create Java source files from w开发者_如何学Chat you are doing in browser. But all these sources result in some Unit Test. For Java I believe JUnit and some other are supported by Selenium IDE.

But I want to ask, why? I mean, if you still need to compile them before executing, why are Unit Tests used instead of just running the code and look if WebDriver throwns any exception? What is the advantage of using for example JUnit here? I know its mostly used this way, I just don´t know why. Thanks.


Here's a couple of reasons off the top of my head:

1) You can hook your selenium tests into your build process (and hence your CI process).

2) You can use JUnit assertions.

3) You can build up multiple suites of JUnit tests (which can then be run in parallel).

I'm sure there's more but I guess it depends on the number of tests you have and the size of the project you are working on. If you're project already has a set of JUnit tests then it's quite nice to be able to write selenium tests without too much effort.


If you use Junit you can quickly recover from failures before starting a new test with the @before and @after annotations. You can also TearDown the tests with it. This also makes the tests more organized.


Not always you get an exception. Your application can handle an exception/user input/ etc. and navigate to different page then expected without throwing an exception - that can be easily verified by JUnit - assert expepected title of a page / presence of an element with actual values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜