I have the following method with no modifier declared exactly in my Column class.
float maximumActiveDutyCycle(ArrayList<Column> columns)
{
// TODO: change public back to default
float maximumActiveDutyCycle = 0.0f;
for (Column column : columns)
{
if (column.activeDutyCycle > maximumActiveDutyCycle)
{
maximumActiveDutyCycle = column.activeDutyCycle;
}
}
return maximumActiveDutyCycle;
}
But I also have the following test method in class TestColumn. I was wondering if someone could tell me how I should test my method since I don’t know how to access it from the Test class. Thanks!
public void testMaximumActiveDutyCycle()
{
this.column00.setActiveDutyCylce(1.1f);
this.column01.setActiveDutyCylce(1.3f);
this.column33.setActiveDutyCylce(1.35f);
this.column57.setActiveDutyCylce(1.355f);
Set<Column> columns = new HashSet<Column>();
columns.add(column00);
columns.add(column01);
columns.add(column33);
columns.add(column57);
}
Ideally, your unit test class should reside in the same class path package as your class.
So in your unit test class, you could access the method that has package access visibility:
Code example:
src/main/java/sg/java/test
src/test/java/sg/java/test
EDIT: Changed the unit test’s class name, should be post fixed with
Testinstead of prefixed. While the method name should be prefixed withtestby convention.