Loading ...
Sorry, an error occurred while loading the content.

[junit] How to add Parameterized Class in TestSuite in Junit

Expand Messages
  • _harry_
    Hi, I want to add Parametrized Class into TestSuite. How can I do that? I did the following: public class SimpleSearches extends SeleneseTestCase { public
    Message 1 of 5 , Jun 1, 2010
    • 0 Attachment
      Hi,

      I want to add Parametrized Class into TestSuite. How can I do that?

      I did the following:

      public class SimpleSearches extends SeleneseTestCase {

      public static Test suite() {
      TestSuite suite = new TestSuite();
      suite.addTestSuite(FibonacciTest.class);
      suiteCount = suite.testCount();
      return suite;
      }

      public static void main(String[] args) {
      junit.textui.TestRunner.run(suite());
      }
      }


      FibonacciTest is a parameterized Class:

      @RunWith(Parameterized.class)
      public class FibonacciTest extends SeleneseTestCase {
      @Parameters
      public static Collection<Object[]> data() {
      return Arrays.asList(new Object[][] {
      Fibonacci,
      { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
      4, 3 }, { 5, 5 },
      { 6, 8 } } });
      }

      private int fInput;
      private int fExpected;

      public FibonacciTest(int input, int expected) {
      fInput= input;
      fExpected= expected;
      }

      public FibonacciTest(String name) {
      super(name);
      }

      @Test
      public void test(@HeresHowYouGetValue Type value) {
      assertAnswerKey(new Object[][] {
      Fibonacci,
      { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
      4, 3 }, { 5, 5 },
      { 6, 8 } } });
      assertEquals(fExpected, Fibonacci.compute(fInput));
      }
      }


      But when I run the Suite file, it creates only one case with fInput and
      fExpected value assigned as Zero.

      But I want all the cases for febonicci to run. How can I do that.
      --
      View this message in context: http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28740497.html
      Sent from the JUnit - User mailing list archive at Nabble.com.
    • Mike Forsberg
      This looks like a promising Google hit.. http://www.javabeat.net/tips/159-junit-40-example.html ... [Non-text portions of this message have been removed]
      Message 2 of 5 , Jun 1, 2010
      • 0 Attachment
        This looks like a promising Google hit..

        http://www.javabeat.net/tips/159-junit-40-example.html

        On Tue, Jun 1, 2010 at 6:22 AM, _harry_ <Harjit.Singh@...> wrote:

        >
        >
        >
        > Hi,
        >
        > I want to add Parametrized Class into TestSuite. How can I do that?
        >
        > I did the following:
        >
        > public class SimpleSearches extends SeleneseTestCase {
        >
        > public static Test suite() {
        > TestSuite suite = new TestSuite();
        > suite.addTestSuite(FibonacciTest.class);
        > suiteCount = suite.testCount();
        > return suite;
        > }
        >
        > public static void main(String[] args) {
        > junit.textui.TestRunner.run(suite());
        > }
        > }
        >
        > FibonacciTest is a parameterized Class:
        >
        > @RunWith(Parameterized.class)
        > public class FibonacciTest extends SeleneseTestCase {
        > @Parameters
        > public static Collection<Object[]> data() {
        > return Arrays.asList(new Object[][] {
        > Fibonacci,
        > { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
        > 4, 3 }, { 5, 5 },
        > { 6, 8 } } });
        > }
        >
        > private int fInput;
        > private int fExpected;
        >
        > public FibonacciTest(int input, int expected) {
        > fInput= input;
        > fExpected= expected;
        > }
        >
        > public FibonacciTest(String name) {
        > super(name);
        > }
        >
        > @Test
        > public void test(@HeresHowYouGetValue Type value) {
        > assertAnswerKey(new Object[][] {
        > Fibonacci,
        > { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
        > 4, 3 }, { 5, 5 },
        > { 6, 8 } } });
        > assertEquals(fExpected, Fibonacci.compute(fInput));
        > }
        > }
        >
        > But when I run the Suite file, it creates only one case with fInput and
        > fExpected value assigned as Zero.
        >
        > But I want all the cases for febonicci to run. How can I do that.
        > --
        > View this message in context:
        > http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28740497.html
        > Sent from the JUnit - User mailing list archive at Nabble.com.
        >
        >
        >


        [Non-text portions of this message have been removed]
      • _harry_
        Thanks for the reply Mike... Yeah I have already added class file in a test suite like the way mentioned in junit example on the link provided. But my
        Message 3 of 5 , Jun 1, 2010
        • 0 Attachment
          Thanks for the reply Mike...

          Yeah I have already added class file in a test suite like the way mentioned
          in junit example on the link provided.

          But my requirement is to add parameterized class and some cases from another
          Class into Test Suite file. Is it possible in jUnit 4.

          The following is not working:

          public static Test suite() {
          TestSuite suite= new TestSuite();
          suite.addTest(new SearchWeb("searchPrimeMinister"));
          suite.addTestSuite(ParameterizedFactorial.class);
          suiteCount = suite.testCount();
          return suite;
          }

          Can we add specific tests instead of class in @...:

          @...({StackTest.class})

          Regards


          Mike Forsberg-2 wrote:
          >
          > This looks like a promising Google hit..
          >
          > http://www.javabeat.net/tips/159-junit-40-example.html
          >
          > On Tue, Jun 1, 2010 at 6:22 AM, _harry_ <Harjit.Singh@...>
          > wrote:
          >
          >>
          >>
          >>
          >> Hi,
          >>
          >> I want to add Parametrized Class into TestSuite. How can I do that?
          >>
          >> I did the following:
          >>
          >> public class SimpleSearches extends SeleneseTestCase {
          >>
          >> public static Test suite() {
          >> TestSuite suite = new TestSuite();
          >> suite.addTestSuite(FibonacciTest.class);
          >> suiteCount = suite.testCount();
          >> return suite;
          >> }
          >>
          >> public static void main(String[] args) {
          >> junit.textui.TestRunner.run(suite());
          >> }
          >> }
          >>
          >> FibonacciTest is a parameterized Class:
          >>
          >> @RunWith(Parameterized.class)
          >> public class FibonacciTest extends SeleneseTestCase {
          >> @Parameters
          >> public static Collection<Object[]> data() {
          >> return Arrays.asList(new Object[][] {
          >> Fibonacci,
          >> { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
          >> 4, 3 }, { 5, 5 },
          >> { 6, 8 } } });
          >> }
          >>
          >> private int fInput;
          >> private int fExpected;
          >>
          >> public FibonacciTest(int input, int expected) {
          >> fInput= input;
          >> fExpected= expected;
          >> }
          >>
          >> public FibonacciTest(String name) {
          >> super(name);
          >> }
          >>
          >> @Test
          >> public void test(@HeresHowYouGetValue Type value) {
          >> assertAnswerKey(new Object[][] {
          >> Fibonacci,
          >> { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
          >> 4, 3 }, { 5, 5 },
          >> { 6, 8 } } });
          >> assertEquals(fExpected, Fibonacci.compute(fInput));
          >> }
          >> }
          >>
          >> But when I run the Suite file, it creates only one case with fInput and
          >> fExpected value assigned as Zero.
          >>
          >> But I want all the cases for febonicci to run. How can I do that.
          >> --
          >> View this message in context:
          >> http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28740497.html
          >> Sent from the JUnit - User mailing list archive at Nabble.com.
          >>
          >>
          >>
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >

          --
          View this message in context: http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28750712.html
          Sent from the JUnit - User mailing list archive at Nabble.com.
        • Mike Forsberg
          I might look at this when I get home, but I think a sibling annotation to @Suite.SuiteClasses is lacking. I d like to see an annotation called
          Message 4 of 5 , Jun 2, 2010
          • 0 Attachment
            I might look at this when I get home, but I think a sibling annotation to
            @... is lacking.

            I'd like to see an annotation called @...... where you can add
            just a specific test.

            In fact I'll add the issue on GitHub, please vote for it.

            If I have some free time I might submit a patch.

            Big Mike

            On Wed, Jun 2, 2010 at 1:45 AM, _harry_ <Harjit.Singh@...> wrote:

            >
            >
            >
            > Thanks for the reply Mike...
            >
            > Yeah I have already added class file in a test suite like the way mentioned
            > in junit example on the link provided.
            >
            > But my requirement is to add parameterized class and some cases from
            > another
            > Class into Test Suite file. Is it possible in jUnit 4.
            >
            > The following is not working:
            >
            >
            > public static Test suite() {
            > TestSuite suite= new TestSuite();
            > suite.addTest(new SearchWeb("searchPrimeMinister"));
            > suite.addTestSuite(ParameterizedFactorial.class);
            > suiteCount = suite.testCount();
            > return suite;
            > }
            >
            > Can we add specific tests instead of class in @...:
            >
            > @...({StackTest.class})
            >
            > Regards
            >
            >
            > Mike Forsberg-2 wrote:
            > >
            > > This looks like a promising Google hit..
            > >
            > > http://www.javabeat.net/tips/159-junit-40-example.html
            > >
            > > On Tue, Jun 1, 2010 at 6:22 AM, _harry_ <Harjit.Singh@...<Harjit.Singh%40fisglobal.com>
            > >
            > > wrote:
            > >
            > >>
            > >>
            > >>
            > >> Hi,
            > >>
            > >> I want to add Parametrized Class into TestSuite. How can I do that?
            > >>
            > >> I did the following:
            > >>
            > >> public class SimpleSearches extends SeleneseTestCase {
            > >>
            > >> public static Test suite() {
            > >> TestSuite suite = new TestSuite();
            > >> suite.addTestSuite(FibonacciTest.class);
            > >> suiteCount = suite.testCount();
            > >> return suite;
            > >> }
            > >>
            > >> public static void main(String[] args) {
            > >> junit.textui.TestRunner.run(suite());
            > >> }
            > >> }
            > >>
            > >> FibonacciTest is a parameterized Class:
            > >>
            > >> @RunWith(Parameterized.class)
            > >> public class FibonacciTest extends SeleneseTestCase {
            > >> @Parameters
            > >> public static Collection<Object[]> data() {
            > >> return Arrays.asList(new Object[][] {
            > >> Fibonacci,
            > >> { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
            > >> 4, 3 }, { 5, 5 },
            > >> { 6, 8 } } });
            > >> }
            > >>
            > >> private int fInput;
            > >> private int fExpected;
            > >>
            > >> public FibonacciTest(int input, int expected) {
            > >> fInput= input;
            > >> fExpected= expected;
            > >> }
            > >>
            > >> public FibonacciTest(String name) {
            > >> super(name);
            > >> }
            > >>
            > >> @Test
            > >> public void test(@HeresHowYouGetValue Type value) {
            > >> assertAnswerKey(new Object[][] {
            > >> Fibonacci,
            > >> { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
            > >> 4, 3 }, { 5, 5 },
            > >> { 6, 8 } } });
            > >> assertEquals(fExpected, Fibonacci.compute(fInput));
            > >> }
            > >> }
            > >>
            > >> But when I run the Suite file, it creates only one case with fInput and
            > >> fExpected value assigned as Zero.
            > >>
            > >> But I want all the cases for febonicci to run. How can I do that.
            > >> --
            > >> View this message in context:
            > >>
            > http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28740497.html
            > >> Sent from the JUnit - User mailing list archive at Nabble.com.
            > >>
            > >>
            > >>
            > >
            > >
            > > [Non-text portions of this message have been removed]
            > >
            > >
            > >
            >
            > --
            > View this message in context:
            > http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28750712.html
            >
            > Sent from the JUnit - User mailing list archive at Nabble.com.
            >
            >
            >


            [Non-text portions of this message have been removed]
          • _harry_
            I dont know how to vote on GitHub. Can you send me the link where and How I have to vote.... Regards ... -- View this message in context:
            Message 5 of 5 , Jun 2, 2010
            • 0 Attachment
              I dont know how to vote on GitHub.

              Can you send me the link where and How I have to vote....

              Regards



              Mike Forsberg-2 wrote:
              >
              > I might look at this when I get home, but I think a sibling annotation to
              > @... is lacking.
              >
              > I'd like to see an annotation called @...... where you can
              > add
              > just a specific test.
              >
              > In fact I'll add the issue on GitHub, please vote for it.
              >
              > If I have some free time I might submit a patch.
              >
              > Big Mike
              >
              > On Wed, Jun 2, 2010 at 1:45 AM, _harry_ <Harjit.Singh@...>
              > wrote:
              >
              >>
              >>
              >>
              >> Thanks for the reply Mike...
              >>
              >> Yeah I have already added class file in a test suite like the way
              >> mentioned
              >> in junit example on the link provided.
              >>
              >> But my requirement is to add parameterized class and some cases from
              >> another
              >> Class into Test Suite file. Is it possible in jUnit 4.
              >>
              >> The following is not working:
              >>
              >>
              >> public static Test suite() {
              >> TestSuite suite= new TestSuite();
              >> suite.addTest(new SearchWeb("searchPrimeMinister"));
              >> suite.addTestSuite(ParameterizedFactorial.class);
              >> suiteCount = suite.testCount();
              >> return suite;
              >> }
              >>
              >> Can we add specific tests instead of class in @...:
              >>
              >> @...({StackTest.class})
              >>
              >> Regards
              >>
              >>
              >> Mike Forsberg-2 wrote:
              >> >
              >> > This looks like a promising Google hit..
              >> >
              >> > http://www.javabeat.net/tips/159-junit-40-example.html
              >> >
              >> > On Tue, Jun 1, 2010 at 6:22 AM, _harry_
              >> <Harjit.Singh@...<Harjit.Singh%40fisglobal.com>
              >> >
              >> > wrote:
              >> >
              >> >>
              >> >>
              >> >>
              >> >> Hi,
              >> >>
              >> >> I want to add Parametrized Class into TestSuite. How can I do that?
              >> >>
              >> >> I did the following:
              >> >>
              >> >> public class SimpleSearches extends SeleneseTestCase {
              >> >>
              >> >> public static Test suite() {
              >> >> TestSuite suite = new TestSuite();
              >> >> suite.addTestSuite(FibonacciTest.class);
              >> >> suiteCount = suite.testCount();
              >> >> return suite;
              >> >> }
              >> >>
              >> >> public static void main(String[] args) {
              >> >> junit.textui.TestRunner.run(suite());
              >> >> }
              >> >> }
              >> >>
              >> >> FibonacciTest is a parameterized Class:
              >> >>
              >> >> @RunWith(Parameterized.class)
              >> >> public class FibonacciTest extends SeleneseTestCase {
              >> >> @Parameters
              >> >> public static Collection<Object[]> data() {
              >> >> return Arrays.asList(new Object[][] {
              >> >> Fibonacci,
              >> >> { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
              >> >> 4, 3 }, { 5, 5 },
              >> >> { 6, 8 } } });
              >> >> }
              >> >>
              >> >> private int fInput;
              >> >> private int fExpected;
              >> >>
              >> >> public FibonacciTest(int input, int expected) {
              >> >> fInput= input;
              >> >> fExpected= expected;
              >> >> }
              >> >>
              >> >> public FibonacciTest(String name) {
              >> >> super(name);
              >> >> }
              >> >>
              >> >> @Test
              >> >> public void test(@HeresHowYouGetValue Type value) {
              >> >> assertAnswerKey(new Object[][] {
              >> >> Fibonacci,
              >> >> { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, {
              >> >> 4, 3 }, { 5, 5 },
              >> >> { 6, 8 } } });
              >> >> assertEquals(fExpected, Fibonacci.compute(fInput));
              >> >> }
              >> >> }
              >> >>
              >> >> But when I run the Suite file, it creates only one case with fInput
              >> and
              >> >> fExpected value assigned as Zero.
              >> >>
              >> >> But I want all the cases for febonicci to run. How can I do that.
              >> >> --
              >> >> View this message in context:
              >> >>
              >> http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28740497.html
              >> >> Sent from the JUnit - User mailing list archive at Nabble.com.
              >> >>
              >> >>
              >> >>
              >> >
              >> >
              >> > [Non-text portions of this message have been removed]
              >> >
              >> >
              >> >
              >>
              >> --
              >> View this message in context:
              >> http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28750712.html
              >>
              >> Sent from the JUnit - User mailing list archive at Nabble.com.
              >>
              >>
              >>
              >
              >
              > [Non-text portions of this message have been removed]
              >
              >
              >

              --
              View this message in context: http://old.nabble.com/How-to-add-Parameterized-Class-in-TestSuite-in-Junit-tp28740497p28763523.html
              Sent from the JUnit - User mailing list archive at Nabble.com.
            Your message has been successfully submitted and would be delivered to recipients shortly.