Custom Reporters

Building Reporters

You can also build your own reporters by implementing our core interface: testbox.system.reporters.IReport
1
interface{
2
3
/**
4
* Get the name of the reporter
5
*/
6
function getName();
7
8
/**
9
* Do the reporting thing here using the incoming test results
10
* The report should return back in whatever format they desire and should set any
11
* Specifc browser types if needed.
12
* @results.hint The instance of the TestBox TestResult object to build a report on
13
* @testbox.hint The TestBox core object
14
* @options.hint A structure of options this reporter needs to build the report with
15
*/
16
any function runReport(
17
required testbox.system.TestResult results,
18
required testbox.system.TestBox testbox,
19
struct options={} );
20
}
Copied!

Executing Your Reporter

Once you implement your own report you just need to pass the class path or the instance of your reporter to the TestBox runner methods using the reporter argument. The reporter argument can be the following values:
  • string - The class path of your reporter
  • instance - The instance of your reporter CFC
  • struct - A structure representing your reporter with the following keys: { type="class_path", options={}. This is mostly used if you want to instantiate and use your reporter with a structure of options.
Now you can init TestBox with your reporter:
1
r = new TestBox( reporter="my.path.toCustomReporter" );
2
r = new TestBox( reporter= new my.path.CustomReporter() );
3
r = new TestBox( reporter={
4
type = "my.path.to.CustomReporter",
5
options = { name = value, name2 = value2 }
6
} );
Copied!

Sample Reporter

Here is a sample reporter for you that generates JSON for the output.
1
component{
2
3
function init(){ return this; }
4
5
/**
6
* Get the name of the reporter
7
*/
8
function getName(){
9
return "JSON";
10
}
11
12
/**
13
* Do the reporting thing here using the incoming test results
14
* The report should return back in whatever format they desire and should set any
15
* Specifc browser types if needed.
16
* @results.hint The instance of the TestBox TestResult object to build a report on
17
* @testbox.hint The TestBox core object
18
* @options.hint A structure of options this reporter needs to build the report with
19
*/
20
any function runReport(
21
required testbox.system.TestResult results,
22
required testbox.system.TestBox testbox,
23
struct options={}
24
){
25
getPageContext().getResponse().setContentType( "application/json" );
26
return serializeJSON( arguments.results.getMemento() );
27
}
28
29
}
Copied!