Fastpoint
级别: 总版主
精华:
44
发帖: 5033
基地声望: 390 点
基地币: 1683 Bug
基地贡献: 0 点
好评度: 15 点
在线时间:818(小时)
注册时间:2005-10-08
最后登录:2008-07-22
|
[FAQ]JUnit 测试用例(TestCase)构造
引用Kent Beck, Erich Gamma,连接地址:http://junit.sourceforge.net/doc/cookbook/cookbook.htm
How do you write and invoke an individual test case when you have a Fixture?
Writing a test case without a fixture is simple- override runTest in an anonymous subclass of TestCase. You write test cases for a Fixture the same way, by making a subclass of TestCase for your set up code and then making anonymous subclasses for the individual test cases. However, after a few such tests you would notice that a large percentage of your lines of code are sacrificed to syntax.
JUnit provides a more concise way to write a test against a Fixture. Here is what you do:
1.Write the test case method in the fixture class. Be sure to make it public, or it can't be invoked through reflection. 2.Create an instance of the TestCase class and pass the name of the test case method to the constructor.
For example, to test the addition of a Money and a MoneyBag, write:
public void testMoneyMoneyBag() { // [12 CHF] + [14 CHF] + [28 USD] == {[26 CHF][28 USD]} Money bag[]= { f26CHF, f28USD }; MoneyBag expected= new MoneyBag(bag); assertEquals(expected, f12CHF.add(f28USD.add(f14CHF))); }
Create an instance of of MoneyTest that will run this test case like this: new MoneyTest("testMoneyMoneyBag") When the test is run, the name of the test is used to look up the method to run. Once you have several tests, organize them into a Suite.
[ 此贴被Fastpoint在2005-10-17 11:02重新编辑 ]
|
可不可不要这么样徘徊在目光内 你会察觉到我根本寂寞难耐 即使千多百个深夜曾在梦境内 我有吻过你这毕竟并没存在
人声车声开始消和逝 无声挣扎有个情感奴隶 是我多么的想她 但我偏偏只得无尽叹谓
其实每次见你我也着迷 无奈你我各有角色范围 就算在寂寞梦内超出好友关系 唯在暗里爱你暗里着迷 无谓要你惹上各种问题 共我道别吧别让空虚使我越轨
|
|
[楼 主]
|
Posted: 2005-10-14 19:25 |
| |