Re: to run single test in junit 4 from a main method
David Saff <[email protected]> Wed, 2 Feb 2011 19:47:02 -0500
| Newsgroups | gmane.comp.java.junit.devel |
|---|---|
| Message-ID | <[email protected]> |
(Oops, I dropped the list on the first reply. Re-adding) Inba, For more sophisticated rules about what to include, and what to exclude, see Request.aClass(SomeClass.class).filterWith(myFilter) Check out the docs on Filter and filterWith to move forward from there. Good luck, David On Tue, Feb 1, 2011 at 3:35 PM, Inbaselvan Gandhi <[email protected]> wr= ote: > Thanks David,=A0 i still getting used to Junit. I just tried and it worke= d. > What i couldn't search was for an option to pass a list of methods that i > would like to execute. Say in this case A and C=A0 just not B. I couldn't= even > spot the right docs, if you can help me in this it would be great. > > Regards, > Inba > > > On Tue, Feb 1, 2011 at 2:27 PM, David Saff <[email protected]> wrote: >> >> Because you're running a method in a JUnit-4-style test class, you'll >> need to use the JUnit 4 test-running mechanism, which is in the >> org.junit package. =A0Something like: >> >> JUnitCore core =3D new JUnitCore(); >> core.addListener(new TextListener(new RealSystem())); >> core.run(Request.method(myClass, "methodName")) >> >> Share and enjoy, >> >> =A0 David >> >> On Tue, Feb 1, 2011 at 11:31 AM, inba <[email protected]> wrote: >> > >> > public class TESTCLASS =A0{ >> > >> > =A0 =A0 =A0 =A0@Before >> > =A0 =A0 =A0 =A0public void setUp(){ >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//some setup >> > =A0 =A0 =A0 =A0} >> > >> > =A0 =A0 =A0 =A0@Test >> > =A0 =A0 =A0 =A0public void testA() { >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//some test >> > =A0 =A0 =A0 =A0} >> > >> > =A0 =A0 =A0 =A0@Test >> > =A0 =A0 =A0 =A0public void testB(){ >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//some test >> > =A0 =A0 =A0 =A0} >> > >> > =A0 =A0 =A0 =A0@Test >> > =A0 =A0 =A0 =A0public void testB(){ >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//some test >> > =A0 =A0 =A0 =A0} >> > } >> > >> > To run a single method testB in the above class I have code in a main() >> > as >> > below >> > >> > new TestRunner().start(new >> > String[]{"-c","TESTCLASS","-m","TESTCLASS.testB"}); >> > >> > >> > but this doesn't work and i get an error like this >> > >> > Exception in thread "main" java.lang.Exception: Could not create and r= un >> > test suite: java.lang.ClassCastException: class TESTCLASS at >> > junit.textui.TestRunner.start(TestRunner.java:182) >> > >> > >> > >> > I am trying to execute a method selected in a swing application. At the >> > end >> > i would want to get a list of selected methods in the swing gui to be >> > executed. how do i do this ? >> > >> > >> > -- >> > View this message in context: >> > http://old.nabble.com/to-run-single-test-in-junit-4-from-a-main-method= -tp30814050p30814050.html >> > Sent from the JUnit - Dev mailing list archive at Nabble.com. >> > >> > >> > >> > ----------------------------------------------------------------------= -------- >> > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> > Finally, a world-class log management solution at an even better >> > price-free! >> > Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> > February 28th, so secure your free ArcSight Logger TODAY! >> > http://p.sf.net/sfu/arcsight-sfd2d >> > _______________________________________________ >> > Junit-devel mailing list >> > [email protected] >> > https://lists.sourceforge.net/lists/listinfo/junit-devel >> > > > ---------------------------------------------------------------------------= --- Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires = February 28th, so secure your free ArcSight Logger TODAY! = http://p.sf.net/sfu/arcsight-sfd2d