i have a little weird task. The following (stripped) code is given (but i cannot change / enhance it):
public class CustomTestClass {
/**
* Logger.
*/
private Logger logger = Logger.getLogger("com.custom.testing");
@Test
public void simpleTestCaseOne(){
logger.warning("simpleTestCaseOne: Not yet implemented!");
assertTrue(true);
}
@Test
public void simpleTestCaseTwo(){
logger.warning("simpleTestCaseTwo: Not yet implemented!");
assertTrue(true);
}
}
Right now i use the following Ant-Code to run the tests:
<target name="Junit_Test"
depends="compile.test" description="Custom TestCase Runner">
<junit printsummary="yes" haltonfailure="no" fork="yes">
<jvmarg value="-Djava.util.logging.config.file=res/logging.properties" />
<classpath>
<path refid="tests.class.path" />
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
</fileset>
</classpath>
<test name="com.custom.testing.CustomTestClass"
haltonfailure="no"
todir="${reports.tests}/xml"
methods="simpleTestCaseOne" >
<formatter type="xml" />
</test>
</junit>
</target>
The logging.properties file just defines a ConsoleHandler, FileHandler and an output file for the logger of the TestClass.
When i run the ant script, it actually works fine, but i need to rerun the tests a few times and change the output file for the FileHandler each time.
Is it possible to add/change a FileHandler for the specified Logger without changing code ?
I don’t particularly like this, but…
You could make a logging configuration file with a replaceable token in the value of the property java.util.logging.FileHandler.pattern, e.g.
Then you could use the Ant copy task with a filterset to substitute the token, e.g.
You would do the copy before each execution of your unit tests, specifying a different value each time.