Selenium with Junit in Eclipse concerns

42 views
Skip to first unread message

Sats

unread,
Aug 18, 2010, 9:01:33 AM8/18/10
to Selenium Users
Hi all,

I am new to Junit in Eclipse...
I have few test cases in Junit and all these tests cases are running
fine individually and also I tried to run it as a package and it runs
fine there as well... but i have two concerns here:

1. When I run the test cases as a package, it is running randomly not
in a sequence.
2. Can I be able to generate a report at the end of the tests?

I have tried to make testsuite, but not successful with that....

Can you guys help me with that... Any suggestion or help would be much
appreciated

Many Thanks
Sats

ranjith

unread,
Aug 18, 2010, 9:31:43 AM8/18/10
to Selenium Users
Hi Sats,

This is the most repeated question in this forum.
Anyway find the below java class which uses JUnit to create TestSuite.

--------------------------------------------------
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class MyTestSuite extends TestCase
{
public static TestSuite suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(TestCase1.class);
suite.addTestSuite(TestCase2.class);
suite.addTestSuite(TestCase3.class);
return suite;
}
}
---------------------------------------------------------

Just you need to replace your java test cases with the TestCase1,
TestCase2 and so on...
For example if you are having two test cases with the names
LoginTest.java, AccountInfo.java then you can add them
as following

suite.addTestSuite(LoginTest.class);
suite.addTestSuite(AccountInfo.class);

Note: If you face any problem with the above code that may be the
class-path issue. So please add junit.jar as a reference library to
your project.

I hope you can understand clearly with my example.

Thanks,
Ranjit

ranjith

unread,
Aug 18, 2010, 9:31:29 AM8/18/10
to Selenium Users

Sathish Kumar

unread,
Aug 18, 2010, 10:15:49 AM8/18/10
to seleniu...@googlegroups.com
Hi Ranjith and the rest of the group ...

Thanks for the detailed explanation... That was very nice....
I tried this before and i have got an error as well: Let me describe what i did so that u can figure where I went wrong:
I have created 3 JUnit tests cases namely test1.java, test2.java, test3.java and all these tests are running fine invididually and all are under the default package....
Then I created a JUnit testsuite named AllTests (default name), no classes were there, so i just clicked finish and it also came under the default package. Then I wrote the below code in it:


import junit.framework.TestCase;
import junit.framework.TestSuite;

public class AllTests extends TestCase

{
public static TestSuite suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(test1.class); {Error in the highlighted}
suite.addTestSuite(test2.class); {Error in the highlighted}
suite.addTestSuite(test3.class);{Error in the highlighted}
return suite;
}
}
I feel like I am doing a big mistake somewhere... Can you please figure it out and help me with that...
One more thing, the Junit.jar file is included in the reference libraries...




Cheers
Sats



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Niraj Kumar

unread,
Aug 18, 2010, 10:19:32 AM8/18/10
to seleniu...@googlegroups.com
The same is posted in this blog . Please go through that and let me know if problem remains

http://automationtricks.blogspot.com/2010/08/how-to-create-test-suite-using-junit.html
--
Thanks & Regard,
Niraj Kumar

Sathish Kumar

unread,
Aug 18, 2010, 10:31:03 AM8/18/10
to seleniu...@googlegroups.com
Okie.. I will have a look Niraj... Thanks a lot indeed...

Sathish Kumar

unread,
Aug 18, 2010, 12:19:23 PM8/18/10
to seleniu...@googlegroups.com
Sorry to say that...
It doesn't work guys...
Same error at the same place...

Vasavi Kaza

unread,
Aug 18, 2010, 1:13:43 PM8/18/10
to seleniu...@googlegroups.com
I have created test suites and they run fine when I run them from eclipse.  I tried running the test suite from terminal from prompt but see the following error.  Can anyone help.  I tried running the test suite class from its folder location.  This is the error I am seeing after running 
java AllTests

Exception in thread "main" java.lang.NoClassDefFoundError: AllTests (wrong name: com/testscripts/ie/AllTests)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

This is my test suite program:

import junit.framework.Test;
import junit.framework.TestSuite;

public class AllTests {

    public static Test suite() {
        TestSuite suite = new TestSuite(AllTests.class.getName());
        //$JUnit-BEGIN$
        suite.addTestSuite(MusicTop100IE.class);
        suite.addTestSuite(SportsHomeIE.class);
        suite.addTestSuite(VideoExploreIE.class);
        suite.addTestSuite(MoviesShowtimesIE.class);
        suite.addTestSuite(FinanceInvestingIE.class);
        suite.addTestSuite(MusicHomeIE.class);
        suite.addTestSuite(FinanceIE.class);
        suite.addTestSuite(FinancePersonalIE.class);
        suite.addTestSuite(MailIE.class);
        suite.addTestSuite(AutosGreencenterIE.class);
        suite.addTestSuite(TvVideosIE.class);
        suite.addTestSuite(FinanceTechtickerIE.class);
        suite.addTestSuite(OmgNewsIE.class);
        suite.addTestSuite(VideoHomeIE.class);
        suite.addTestSuite(ShoppingHomeIE.class);
        suite.addTestSuite(AllNewEmailTest.class);
        suite.addTestSuite(MoviesComingsoonIE.class);
        suite.addTestSuite(FinanceNewsIE.class);
        suite.addTestSuite(TvListingsIE.class);
        suite.addTestSuite(TvBlogIE.class);
        suite.addTestSuite(TvHomeIE.class);
        suite.addTestSuite(MoviesHomeIE.class);
        suite.addTestSuite(NewsHomeIE.class);
        suite.addTestSuite(OmgHomeIE.class);
        //$JUnit-END$
        return suite;
    }
   
    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}

-  Vasavi

Andy Mao

unread,
Aug 18, 2010, 9:31:56 PM8/18/10
to seleniu...@googlegroups.com
Your test1 and AllTests class should in the same package, you must make sure AllTests can refer test1 class.

All the best
Andy

2010/8/19 Sathish Kumar <satd...@gmail.com>
Reply all
Reply to author
Forward
0 new messages