这个模式非常简单:就像行为没有实现方面那样为系统编写一个测试。
This pattern is very simple: write a test against your system as you would if the behavior were not implemented with aspects.
为用作示例,我将编写一个测试,模拟用户选择0行处组合框中的第二个元素。
As an example, I'll write a test that simulates a user selecting the second element in the combo box at row 0. The actions for the test to perform are.
为Account 的withdraw()方法编写一个测试。
Write a test for the withdraw() method on Account. Your test should now look like Listing 6
接下来,您想要编写一个测试,不仅要验证输出得到了显示,还要验证输出是正确的。
Next, you want to write a test that verifies not only that the output is present, but that it's correct. There are two ways you can do this
现在,可以编写一个测试脚本并与测试应用程序一起运行,以检验测试中的组件。
A test script can now be written and run with this test application to exercise the component under test.
在编写一个测试来表达您试图实现的结果之后,您可以一直调试直到测试结果是良性的。
After writing a test that expresses the result you're trying to achieve, you then debug until the test is positive.
您首先想到的可能是:到重构的时间了,但这样做将打破第一个重构规则,即将编写一个测试用例。
Your first thought could be that it's time to refactor, but doing so would break the first rule of refactoring, which is to write a test case.
所以,换句话说,要使用我的策略,只需编写一个测试案例类,然后总是将其部署到客户机和服务器就可以了。
So, in other words, to use my strategy, simply write one test case class, and then always deploy to both the client and the server.
在Wikipedia上查找到前几个完全数之后,我可以编写一个测试,它检查实际上是否可以找到完全数。
After checking with Wikipedia to find the first few perfect Numbers, I can write a test that verifies that I can in fact find perfect Numbers.
这种“编写一个测试,编写足够的代码来使测试通过,重新进行测试”方法是您每天都在经历的XP开发流程。
This "write a test, write just enough code to get it to pass, rerun the test" approach is the xp development flow that you should experience every day.
这样的情景您也许并不陌生:您在编写一个测试程序,程序需要暂停一段时间,于是调用Thread .sleep 。
This story is probably familiar: you're writing a test program and you need to pause for some amount of time, so you call Thread.sleep .
从功能性观点考虑,您或许希望编写一个测试:填入表单值,单击Submit按钮,然后验证表单是否显示定义。
From a functional standpoint, you'd probably want to write a test to fill in the form value, click the Submit button, and then verify the presence of the definition under the form.
编写一个测试清理方面,自动在每次测试后像在例子中那样重新设置方面从概念上来说是简单的,但是其细节超出了本文的范围。
Writing a test-cleanup aspect to automatically reset aspects like the one in the example after each test is conceptually simple, but the details are beyond the scope of this article.
当每个方法都有了至少一个测试,使用一个代码覆盖率工具如cobertura为每个分支编写一个测试,直到每一行代码都能够被测试。
Once every method has at least one test, use a code coverage tool, such as Cobertura, to write one test for every branch until each line of code is tested.
产品发布以后,如果发现了一个缺陷,我们会编写一个测试,并且在所有的版本中进行验证,看看这个缺陷是不是已经在某个版本里面被修复了。
When a bug is found after a product has been released, a test is written and verified against all channel builds to see if the bug has already been fixed in one of the channels.
下一步是编写一个简单的测试脚本,这个脚本将一个条目添加到队列中。
The next step is to write a simple test script that adds an entry to the queue.
可以为那些代码片段编写更多的失败测试,直到一个合理的规范开始成形。
More failing tests could be written for those pieces of code until a reasonable specification begins to take shape.
特别是,如果把一个程序自身当作它的输入是会发生什么,我们需要编写一个怎忙的程序来测试它呢?
In particular, what if we decided we wanted to write a program that would test what happens when we run a program on itself as input.
您不能以递增方式生成窗体设计器—也就是说,您不能实现一个服务,测试应用程序,然后编写另一个服务。
You can't build the forms designer incrementally-that is, you can't implement one service, test the application, and then write another service.
对于那些希望编写一个新的测试框架的人员而言,门槛降低了。
For those who want to write a new test framework, the barrier for entry is lower.
应该遵循下面这条很好的原则:即只要您认为有必要对代码中的某个行为加注,就编写一个单元测试。
A good guideline to follow is to write a unit test whenever you feel the need to comment some behavior in the code.
在你所使用的开发工具的需求,和另一个群件编写代码的需求以及和另一个群件运行测试的需求之间跟毫无联系。
There was no connection between the requirements that you created with one of the suite tools, the code you wrote with another, and the tests you ran with yet another.
另一方面,我们一直计划“不久以后”编写的测试套件存在一个重大且明显的差距;越早构建更多的测试支持,使用它节省的时间就越多。
On the other hand, the test suite we keep planning to write "soon" has been a major and noticeable gap; building more testing support earlier and using it more could have saved a lot of time.
在处理一个新的用户故事时,你发现针对前一个故事所编写的测试已经不再体现需求。
When proceeding to a new story, you discover that a test you wrote for a previous story no longer reflects the requirements.
一种策略是,在编写正在测试的代码时,编写测试程序;另一种策略是,让另一个开发者小组来编写测试程序。
Either you write the test when you write the code being tested, or you have another team of developers write the tests.
以为通过在白板上编写一个个测试用例就可以产生清晰架构的想法简直就是胡闹。
The notion that you can generate a viable architecture by starting with a blank screen and then writing one test case after the other is sheer folderol.
如果你想自己动手开始工作,那么你需要开发enterprisebean并在服务器端部署它,以便你可以编写一个JUnitEE来测试它。
If you were to start on your own, you would need to develop an Enterprise bean and deploy it in the server so that you could write a JUnitEE to test it.
刚编好这个方法,我还没注意到这个缺陷,但由于我狂热地崇拜开发人员测试,于是我编写了一个使用TestNG的常规测试。
Having just coded the method, I haven't yet noticed the defect, but because I'm a developer testing fanatic, I write a routine test using TestNG.
JUnit提供一个用于编写测试的模板,该模板可以安装、执行和卸载。
It provides a template for writing tests with setup, execution, and teardown.
现在,我们编写一个探索测试,它将访问公共提要并将结果转储到stdout以便进行分析,如清单8所示。
In keeping with the progression so far, let's write an exploration test that hits the public feed and dumps the results to stdout for examination, shown in Listing 8.
应用推荐