Skip to content

TestListener Interface

itaiag edited this page Aug 9, 2016 · 1 revision

TestListener Interface

The system object can implement the interface “junit.framework.TestListener” method. By doing so, the system object will be signaled upon test execution of events. An example of a system object that implements the “TestListener” interface is as follows: The “addError”, “addFailure","endTest” and “startTest” are “TestListener” methods. The “startTest” and “endTest” are invoked whenever a test starts and or ends the “addError” is called whenever a test fails due to execution error; the “addFailure” method is called whenever a test fails due to assertion problem.

TestListener Class Code Example

package com.aqua.services.systemobject;
import jsystem.framework.system.SystemObjectImpl;
import jsystem.utils.FileUtils;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestListener;
public class HelloWorldWithTestListener extends SystemObjectImpl implements TestListener{
	private String message;
	private String fileName;
	public void init() throws Exception {
		super.init();
		report.report("Hello world init");
	}
	public void close(){
		report.report("Hello world close");
		super.close();
	}
	public void getHelloMessage() throws Exception {
		report.report("Hello Message",getMessage(),true);
	}
	public void readFromFile() throws Exception {
		String textFromFile = FileUtils.read(getFileName());
		setTestAgainstObject(textFromFile);
	}
	public void writeToFile(String text) throws Exception {
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	@Override
	public void addError(Test arg0, Throwable arg1) {
		// Will be called
	}
	@Override
	public void addFailure(Test arg0, AssertionFailedError arg1) {
		// TODO Auto-generated method stub
	}
	@Override
	public void endTest(Test arg0) {
		// TODO Auto-generated method stub
	}
	@Override
	public void startTest(Test arg0) {
		// TODO Auto-generated method stub
	}
}

Clone this wiki locally