如何用多种方法组织一个类的测试用例?

时间:2022-11-14 23:55:28

The application that I'm working on does three things for every input (a unique id)

我正在处理的应用程序为每个输入做了三件事(一个唯一的id)

  1. Extract information from multiple source pertaining to that id
  2. 从与该id相关的多个源中提取信息

  3. Validate the information that I extract

    验证我提取的信息

    2.1 If the validation succeeds then go on to the next extraction

    2.1如果验证成功,则继续进行下一次提取

    2.2 If the validation fails, then do the first step for the next id

    2.2如果验证失败,则执行下一个id的第一步

  4. After extraction is done from all the service, I get all the information, transform and form the value object

    从所有服务中提取完成后,我获取所有信息,转换并形成值对象

For Extraction, I have created a class for every service I'm hitting and getting the information.

对于提取,我已经为我正在打的每个服务创建了一个类并获取信息。

I access the object of the extract classes in the transformation and perform the transformation.

我在转换中访问提取类的对象并执行转换。

My transformation class looks something like this:

我的转换类看起来像这样:

        builder
        .field1(getField1(extract1))
        .field2(getFiedl2(extract1, extract2))
        .field3(getField3(extract3))
        ....
        .field100+(getField(extract..))
    return builder;

Now, I want to write test cases for the transformation I am doing. I am having trouble in organizing the test cases.

现在,我想为我正在进行的转换编写测试用例。我在组织测试用例时遇到了麻烦。

If I create a class for every method, then I would end up in more that 100 classes. Also If I take the approach of 1 test class per class then I would be writing all the test cases in one class and it would become really hard to understand.

如果我为每个方法创建一个类,那么我最终会有100个类。另外如果我采用每个类1个测试类的方法,那么我将在一个类中编写所有测试用例,这将变得非常难以理解。

Could anyone suggest what should be done?

谁能建议应该做些什么?

1 个解决方案

#1


0  

The problem could be that the class you are testing is actually too big itself and needs to be broken down given that you have so many fields. However, I don't know enough to state that categorically.

问题可能是您正在测试的类本身实际上太大而且需要分解,因为您有这么多字段。但是,我不太清楚地说明这一点。

In terms of breaking up the tests in general, you probably want to look at grouping tests of related functionality into their own classes. That way when functionality needs to be changed later, any resulting test failures would likely be limited to a given area of functionality.

就一般的分解测试而言,您可能希望将相关功能的分组测试分组到他们自己的类中。这样,当以后需要更改功能时,任何导致的测试失败都可能仅限于给定的功能区域。

#1


0  

The problem could be that the class you are testing is actually too big itself and needs to be broken down given that you have so many fields. However, I don't know enough to state that categorically.

问题可能是您正在测试的类本身实际上太大而且需要分解,因为您有这么多字段。但是,我不太清楚地说明这一点。

In terms of breaking up the tests in general, you probably want to look at grouping tests of related functionality into their own classes. That way when functionality needs to be changed later, any resulting test failures would likely be limited to a given area of functionality.

就一般的分解测试而言,您可能希望将相关功能的分组测试分组到他们自己的类中。这样,当以后需要更改功能时,任何导致的测试失败都可能仅限于给定的功能区域。