I have a common variable errorCollector
, and the 2 below approaches works for me.
But I cant figure out which is best or which is standard?
Approach 1 : Creating a common class for that variable then extending it.
class QAErrorCollector
{//This class is created only for this variable alone.
@Rule
public ErrorCollector errorCollector = new ErrorCollector();
}
class TestFeatureA extends QAErrorCollector
{
// use errorCollector
}
class TestFeatureB extends QAErrorCollector
{
// use errorCollector
}
Approach 2: Creating 2 different variables for each class. (This approach will work too in test case)
class TestFeatureA
{
@Rule
public ErrorCollector errorCollector = new ErrorCollector();
// use errorCollector
}
class TestFeatureB
{
@Rule
public ErrorCollector errorCollector = new ErrorCollector();
// use errorCollector
}