2008-03-31
JUnit In Action读书笔记(4)
关键字: composing tests with testsuite
2.2 Launching tests with test runners
Writing tests can be fun, but what about the grunt work of running them?
2.2.1 Selecting a test runner
The JUnit distribution includes three TestRunner classes: one for the text console, one for Swing, and even one for AWT (the latter being a legacy that few people still use).
2.2.2 Defining your own test runner
you could also extend this class yourself.
2.3 Composing tests with TestSuite
............
Altogether, this seems simple--at least as far as running a single test case is concerned.
But what happens when you want to run multiple test cases?Or just some of your test cases?How can you group test cases?
JUnit’s answer to this puzzle is the TestSuite. The TestSuite is designed to run one or more test cases. The test runner launches the TestSuite; which test cases to run is up to the TestSuite.
2.3.1 Running the automatic suite
To keep simple things simple, the test runner automatically creates a TestSuite if you don’t provide one of your own. (Sweet!)
The default TestSuite scans your test class for any methods that start with the characters test. Internally, the default TestSuite creates an instance of your TestCase for each testXXX method. (原来是要为每一个testXXX method都新create个instance呀!佩服!!).The name of the method being invoked is passed as the TestCase constructor, so that each instance has a unique identity.
For the TestCalculator, the default TestSuite could be represented in code like this:
public static Test suite(){
return new TestSuite(TestCalculator.class); // (2)
}
(这里的并没有体现出把要测方法的名字传入TestCase的constructor里面当作unique identify吧?倒是下面的(1)处用了"testAdd",难道说JUnit能自动检测出上面的(2)处是想测"add"方法?不对吧.....)
And this is again equivalent to the following:
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new TestCalculator("testAdd")); // --(1)
return suite;
}
the automatic test suite ensures that you don’t forget to add some test to the test suite.
2.3.2 Rolling your own test suite
Writing tests can be fun, but what about the grunt work of running them?
2.2.1 Selecting a test runner
The JUnit distribution includes three TestRunner classes: one for the text console, one for Swing, and even one for AWT (the latter being a legacy that few people still use).
2.2.2 Defining your own test runner
you could also extend this class yourself.
2.3 Composing tests with TestSuite
............
Altogether, this seems simple--at least as far as running a single test case is concerned.
But what happens when you want to run multiple test cases?Or just some of your test cases?How can you group test cases?
JUnit’s answer to this puzzle is the TestSuite. The TestSuite is designed to run one or more test cases. The test runner launches the TestSuite; which test cases to run is up to the TestSuite.
2.3.1 Running the automatic suite
To keep simple things simple, the test runner automatically creates a TestSuite if you don’t provide one of your own. (Sweet!)
The default TestSuite scans your test class for any methods that start with the characters test. Internally, the default TestSuite creates an instance of your TestCase for each testXXX method. (原来是要为每一个testXXX method都新create个instance呀!佩服!!).The name of the method being invoked is passed as the TestCase constructor, so that each instance has a unique identity.
For the TestCalculator, the default TestSuite could be represented in code like this:
public static Test suite(){
return new TestSuite(TestCalculator.class); // (2)
}
(这里的并没有体现出把要测方法的名字传入TestCase的constructor里面当作unique identify吧?倒是下面的(1)处用了"testAdd",难道说JUnit能自动检测出上面的(2)处是想测"add"方法?不对吧.....)
And this is again equivalent to the following:
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new TestCalculator("testAdd")); // --(1)
return suite;
}
the automatic test suite ensures that you don’t forget to add some test to the test suite.
2.3.2 Rolling your own test suite
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 29435 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
链接
最新评论
-
对浏览器中的context menu ...
Drag dropper
-- by whqida -
Spring中的load-time weav ...
没啥,有些class不在spring的管理之中,通过 load-time wea ...
-- by ray_linn -
对浏览器中的context menu ...
别搞笑了, 这是浏览器的 Context Menu? 这只不过是响应了鼠标右击事 ...
-- by fcoffee -
IE tab在Firefox里开发时 ...
firebug只能用于ff, 并不能用于ff下的ietab, 原因显而易见.如果 ...
-- by fcoffee -
IE tab在Firefox里开发时 ...
还网告知 该如何操作呢 我还是要到ie下再调试啊
-- by jianfeng008cn






评论排行榜