views:

1827

answers:

7

I have written tests that are using selenium for functional testing. I'm using Java. I would like to be able to create structure between tests. Is it possible to do it with jUnit or TestNG?

Would like to be able to create test structure that will produce report like this:

Top test FAIL
- Module1 test PASS
-- Module1Class1 test PASS
-- Module1Class2 test PASS
--- Module1Class3Method1 test PASS
--- Module1Class3Method2 test PASS
- Module2 test FAIL
-- Module2Class1 test FAIL
--- Module2Class1Method1 test PASS
--- Module2Class1Method2 test FAIL
--- Module2Class1Method3 test PASS
+1  A: 

You cannot, because this is not the format that Selenium interprets tests. Selenium supports several different language syntaxes, the easiest of which are JS and HTML table rows. You could use the record feature of the Selenium IDE from Firefox if you do not want to hand write your tests to fit a certain language syntax.

Hi. Thanks for answer. But I'm not asking about Selenium syntax. This is question for junit/testng tests results. Maybe I should remove information about Selenium from description not to confuse anyone ;)
Ula Karzelek
Unit tests are tests from within code to analyze if bits of code do as they are intended. That is not what Selenium tests. Selenium tests for what the browser sees post render, which is not what parts of interactive code are written for but rather what an application is written for in full.
+1  A: 

did you consider using Selenium Remote Control? http://seleniumhq.org/projects/remote-control/

Yonatan Karni
I'm using Selenium RC
Ula Karzelek
+1  A: 

I would recommend looking at the JUnit or TestNG XML reports. You should be able to transform them with a bit of XSLT to provide a new HTML report with your required format.

Dave Hunt
A: 

I am not complete sure if i am right here..but i think this can help you: http://www.jamesnetherton.com/blog/2007/07/02/Creating-a-Selenium-test-suite/

You can group your tests with it in an very easy structered way.

bastianneu
Thanks for the idea. My question is more like one comment for this blog post on your site:Posted by Madhavi | Tuesday 22 January 9:01 AM"(...) Do you know any way to inbed one test suite into another. I need to create smaller test suites for each functionality and include those test suites into the master test suite."
Ula Karzelek
from my point of knowledge it is not possible but also not needed. You have to design your code around those test classes not the other way. Sorry, I think your approach is maybe to complex. But an solution would be to design special test suites and place them into packages. So you can test software components via packages. Hope this helps...
bastianneu
Thanks :) The idea behind is to have not only small tests for each functionality but being able to run all of those small grouped on level1, then a few of those grouped on level2 and so on. If the group on level2 (as all in them) fails - then having possibility to dig down to group on level1 and then to the one small test that failed. Isn't it usual practice for writing functional tests?
Ula Karzelek
You have a neat idea there...isn't the same procedure that a lot of people use to learn foreign languages? Talking about Unit testing..i don't know if anybody developed something for this issues. I'm sorry...i can't answer your question.
bastianneu
It looks like digging into testng can help with it. See my last link.
Ula Karzelek
+1  A: 

The best pattern I have seen for organizing the code behind selenium tests is the page object pattern:

http://blog.m.artins.net/acceptance-tests-with-jbehave-selenium-page-objects/

Here's a Java helper library:

http://code.google.com/p/webdriver/wiki/PageFactory

ndp
Interesting, thanks :)
Ula Karzelek
A: 

I just have found the solution for this question so I'm putting here link so that others can benefit from it. beust.com I haven't try that yet, though.

Update: After trying it I can generate results like this:

Module1.Class3.Method1 PASS
Module1.Class3.Method2 PASS
Module2.Class1.Method1 PASS
Module2.Class1.Method2 FAIL
Module2.Class1.Method3 PASS

The fail method name is "Method2" it is located in class "Class1" and it is package "Module2".

I have used all the standard possibilities of TestNG (a lot of it) + I have overwritten the TestListenerAdapter using ITestResult methods: getName() and getTestClass().getName()

It's not really the structure I was looking for, but little bit parsing can tell me where the fail was. And as a plus I don't have to name methods with class and package name in it.

Ula Karzelek
+1 looks nice. Thank you for that link
bastianneu
+1  A: 

In TestNG you can define suites via the configuration file (testng.xml) which should match your needs. You could structure it to have a test group for every Module. A failure in a test group renders the whole test as a failure. But i think you could also do that in JUnit, which i am not too familiar with.

What is nice in TestNG is, that you can define dependencies. These will enforce a certain logical order for test execution and will skip tests that depend on failing tests, instead of letting them fail as well. Makes analysis a lot more easier and tests end earlier because all those tests that are potentially doomed to fail will be left aside.

But like i said earlier, i think you can do that in JUnit as well. It's more a matter of taste. And if you decide otherwise, it is not a big undertaking to convert from JUnit to TestNG or visa versa.

ruby fu novice