你如何组织你的 TestSuite?
我正在尝试在办公室使用Junit(JVM 1.4):我编写了很多扩展TestCase类,但我没有编写任何扩展TestSuite类。 问题是我不太明白 TestSuite 必须测试什么:
包的公共契约(包的所有公共类的所有公共方法)。< br> 示例:
公共类 TestPackageAAA 扩展 TestSuite{ //... 公共无效测试东西{ testSuite.add(new TestFirstClass()); testSuite.add(new TestSecondClass()); } //... }
FirstClass 和 SecondClass 存在于同一个包 AAA 中。
功能流程,翻译成单个类的列表没有集成?
公共类 TestProcessBBB 扩展 TestSuite{ //... 公共无效测试东西{ testSuite.add(new TestFirstClass()); testSuite.add(new TestSecondClass()); } //... }
FirstClass 作为名为 BBB 的用户进程的第一步(如 web 应用程序中的 CRUD 操作),SecondClass 作为同一进程的第二步等等(在此测试中,FirstClass 和 SecondClass 不通信)。
你如何组织你的 TestSuite?采用第一种方式还是第二种方式?或者以另一种方式?
编辑: 我错了,因为我在示例中重复了相同的类名称,ergo 这很令人困惑。 这是示例的配置:
src
|-->{package} **AAA**
|--->{class}FirstClass
|--->{class}SecondClass
|-->{package} **XYZ**
|-->{class}ThirdClass
test
{package} **AAA**
|--->{class}TestFirstClass extends TestCase
|--->{class}TestSecondClass extends TestCase
|-->{package} **XYZ**
|-->{class}TestThirdClass extends TestCase
- 第一种方式:
中所有 TestCase 的组合
testSuite.add(new TestFirstClass());
testSuite.add(new TestSecondClass());
- TestSuiteAAA(放置在测试目录的根目录中)是 test.AAA包 方式:
TestSuiteBBB(放置在测试目录的根目录中)是参与功能流程执行的所有测试用例的组合(例如:为电子商务网站的管理员发送预定的电子邮件)。 TestSuiteBBB 调用 FirstClass 和 ThirdClass 的方法,并且每个类不调用其他类的方法。
testSuite.add(new TestFirstClass());
testSuite.add(new TestThirdClass());
JUnit 允许我以两种方式进行操作(我现在在 Eclipse 中对它们进行编码并运行):您更喜欢什么?
PS 对包结构的格式表示抱歉:)
I'm trying to use Junit at office (JVM 1.4): I wrote a lot of class extending TestCase but I didn't write any class extending TestSuite.
The problem is that I don't understand very well what a TestSuite have to testing:
the public contract of a package(all the public method of all the public class of a package).
Example:public class TestPackageAAA extends TestSuite{ //... public void testSomething{ testSuite.add(new TestFirstClass()); testSuite.add(new TestSecondClass()); } //... }
with FirstClass and SecondClass existing in the same package AAA.
the functional process, translated as a list of single class not integrated?
public class TestProcessBBB extends TestSuite{ //... public void testSomething{ testSuite.add(new TestFirstClass()); testSuite.add(new TestSecondClass()); } //... }
with FirstClass as first step of a user process named BBB (like a CRUD operation in webapp), the SecondClass as second step of the same process etc etc. (in this test, FirstClass and SecondClass don't communicate).
How do you organize your TestSuite? In the first way or second way? Or in another way?
EDIT:
I'm wrong because I repeat the same name of class in the example, ergo it's confusing.
This is the configuration of example:
src
|-->{package} **AAA**
|--->{class}FirstClass
|--->{class}SecondClass
|-->{package} **XYZ**
|-->{class}ThirdClass
test
{package} **AAA**
|--->{class}TestFirstClass extends TestCase
|--->{class}TestSecondClass extends TestCase
|-->{package} **XYZ**
|-->{class}TestThirdClass extends TestCase
- first way:
TestSuiteAAA (placed in the root of testing directory) is a composite of all the TestCase in the package test.AAA
testSuite.add(new TestFirstClass());
testSuite.add(new TestSecondClass());
- second way:
TestSuiteBBB (placed in the root of testing directory) is a composite of all the TestCase partecipating to execution of a functional process (example: sending a scheduled email for the admin of an e-commerce website).
TestSuiteBBB call the methods of FirstClass and ThirdClass and each class don't call the methods of the other class.
testSuite.add(new TestFirstClass());
testSuite.add(new TestThirdClass());
JUnit allow me doing in both way (I coded them now in Eclipse and run): what do you prefer?
PS sorry for the formatting of structure of packages :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,我不知道这是否真的回答了你的问题,但我发现很难理解你的问题。
通常,您在构建过程中会有一个自己的测试目录。如果您使用 Eclipse 或 Netbeans 作为 IDE,您将拥有一个用于源代码 (src) 的文件夹和一个用于测试的文件夹。我们通常在 test 和 src 文件夹中创建相同的包名称。
大多数工具链几乎迫使您使用这种方式来组织测试。
Sorry, I don't know if this really answers your questions, but I find it very hard to understand your question.
Normaly you would have a own test directory in your build process. If you use Eclipse or Netbeans as your IDE, you would have one folder for source (src) and one folder for the tests. We normaly create the same package names in both the test and the src folder.
Most tool-chains pretty much force you to use this way of organizing your tests this way.