Question on addTest method of Junit
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi, all, I got a question on the addTest method of TestSuite class. I wrote a TestSuite class with the static suite method like this:
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(CalTest.class);
return suite;
}
where CalTest is a class inheriting from TestCase class. This part of code is ok. However if I change to this
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new CalTest()); --- difference
return suite;
}
The launch of the testrunner fails and reports a AssertionFailedError. On the JUnit api doc, the addTest(Test test) method does not have any explanation. I would like to know what is wrong with the second method.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(CalTest.class);
return suite;
}
where CalTest is a class inheriting from TestCase class. This part of code is ok. However if I change to this
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new CalTest()); --- difference
return suite;
}
The launch of the testrunner fails and reports a AssertionFailedError. On the JUnit api doc, the addTest(Test test) method does not have any explanation. I would like to know what is wrong with the second method.
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The default constructor doesn't tell Junit which test case to add to the suite. You need to call the constructor that takes a string. For example,
However, this only runs one test. If you want to run all the tests, as I suspect, you can add the whole test suite. There are two ways of doing this (one you already had)
However, this only runs one test. If you want to run all the tests, as I suspect, you can add the whole test suite. There are two ways of doing this (one you already had)
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Boyan Wu
Greenhorn
Posts: 9
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thank you, Jeanne. You solved my puzzle. I used to think the fName private field in the TestCase class indicates the name of the test class, a usual way in designing class though, it turns out this is the method name I want to run.
| His brain is the size of a cherry pit! About the size of this ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











