简体   繁体   English

将参数传递给测试用例

[英]Pass Parameter To Test Case

I have a test case like below: 我有一个如下的测试用例:

@RunWith(Categories.class)
@IncludeCategory(UsageCollectiontNecessaryCategory.class)
@SuiteClasses({
    SampleTest1.class,
    SampleTest2.class,
    SampleTest3.class
})
public class AllTest {

}

Those three test(SampleTest1, SampleTest2 and SampleTest3) will base on the same data to run. 这三个测试(SampleTest1,SampleTest2和SampleTest3)将基于要运行的相同数据。 I want to init the parameter in one place and pass it into the three test class. 我想在一处初始化参数并将其传递给三个测试类。 The parameter is an complex object(not a string or int etc) include many data, How can I do that? 该参数是一个复杂的对象(不是字符串或int等),包含许多数据,该怎么办? Or any other good way to do that? 还是有其他好的方法可以做到这一点?

Without knowing your object I will demonstrate with a string example. 在不知道您的对象的情况下,我将通过字符串示例进行演示。

package com.yang;

public class ObjectData{

    public String object = "I will be used very often";

}

Your Testclasses: 您的测试课程:

package com.yang;

import com.yang.ObjectData;

public class TestOne{

private ObjectData data= new ObjectData();
private String objectInTestClass = new String(data.object);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM