Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Junit4+Eclipse+Selenium RC- Test class should have exactly one public zero-argument constructor

 
Sunny Saeed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to test the 2 pages of an application I have created two classes and then execute them with the 3rd class suite classes.

I am using Selenium RC with Junit 4 + Eclipse. While executing the script the test against the first class passes but while executing the 2nd class the above mentioned error is displayed.

Following are the details of the code:





I have already defined the construcotr of the class Login but the compiler still throws the error.Any help would be highly appreciated?

Regards
ES
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the constructor public Login (Selenium selenium). The error message says you should have a zero argument one as well so you need public Login().
 
Sunny Saeed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeanne for your reply.

When I add public Login() {} constructor, now I receive the message 'java.lang.IllegalArgumentException: Test class can only have one constructor


Any thoughts would be highly appreciated.

Kind regards
EN


 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunny:

A proper JUnit 4 test class uses the default constructor, so don't create one.

John.
 
Sunny Saeed
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne & John any further thoughts? I am stuck on this problem from the last few days.


Kind regards
EN
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunny,

Ok, I think I see the problem, and it doesn't really have anything to do with JUnit 4, Eclipse, or Selenium. You're mixing your page classes and your tests. You probably want to set your test up similar to this layout:



In general, I prefer to separate concerns by having a set of page objects that know their behavior, and use a single Selenium object, and having a set of tests that only use the page classes' interfaces. Also, since you are using Eclipse, you don't need to create a test suite, as Eclipse has a JUnit 4 test runner that will run your test and give you graphical output.

John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic