Tutorial: JUseCase diagnostics

In this tutorial you will learn how to configure log4j to enable the internal diagnostics used in JUseCase.

Why diagnostics?

Let's say your application misbehaves - it doesn't do quite what you expect and it's not obvious why. You go to the source code, add some System.out.println(...) statements, recompile and run a test again. "Aha!" you say, and go back to the source code, add some more debug statements, recompile and run the test once more. You find the bug, correct it and remove the debug statements because you obviously don't want a user to see them. Is this something you recognize? If so, consider using diagnostics.

Diagnostics are basically debug statements describing application behavior or the state of certain data. They should be maintained like the rest of the code, and they should also be configurable at runtime, meaning that all you have to do to turn them on or off is to edit some configuration file (no need to recompile!). Not only is this very convenient, it is also almost essential when using the TextTest approach to testing.

JUseCase diagnostics

If you're having troubles understanding what happens while you're recording or replaying a test using JUseCase, you might want to switch on JUseCase's internal diagnostics which use the log4j package. The easiest way to configure them is to create a normal log4j.properties file (as described on the log4j homepage, see downloads section). Log4j uses a hierarchy structure of loggers, which means that if you enable one logger you also enable all child loggers. The root logger for JUseCase is simply called "jusecase", and here's a list of the rest of the loggers:

A template log4j.properties file is provided below. Check the log4j homepage for details on how to set up loggers and appenders.

# -------------------- LOGGERS -------------------- # The JUseCase loggers are turned on by setting the # logger level to INFO. Loggers are turned off by # setting the level to OFF. # JUseCase root logger log4j.logger.jusecase=OFF, void # Logs setup info, eg files read at startup and # config settings. log4j.logger.jusecase.setup=OFF, void # Logs detailed recording/replaying messages log4j.logger.jusecase.replay=OFF, void log4j.logger.jusecase.record=OFF, void # Logs brief replay feedback messages, what event # is being simulated etc. log4j.logger.jusecase.replay.progress=OFF, void # Logs detailed messages for individual component # recorders/replayers. log4j.logger.jusecase.components.button=OFF, void log4j.logger.jusecase.components.combo=OFF, void log4j.logger.jusecase.components.filechooser=OFF, void log4j.logger.jusecase.components.list=OFF, void log4j.logger.jusecase.components.slider=OFF, void log4j.logger.jusecase.components.table=OFF, void log4j.logger.jusecase.components.tabs=OFF, void log4j.logger.jusecase.components.textfield=OFF, void log4j.logger.jusecase.components.togglebutton=OFF, void log4j.logger.jusecase.components.tree=OFF, void log4j.logger.jusecase.components.window=OFF, void # Turn on/off all component loggers log4j.logger.jusecase.components=OFF, void # -------------------- APPENDERS -------------------- # setup a file appender (dummy) that logs to the file "dummy.txt" log4j.appender.dummy=org.apache.log4j.FileAppender log4j.appender.dummy.File=dummy.txt log4j.appender.dummy.Append=false log4j.appender.dummy.layout=org.apache.log4j.PatternLayout log4j.appender.dummy.layout.ConversionPattern=%m%n # setup a console appender, stdout, that logs to std out log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%m%n # null appender log4j.appender.void=org.apache.log4j.varia.NullAppender log4j.appender.void.layout=org.apache.log4j.PatternLayout log4j.appender.void.layout.ConversionPattern=%m%n

Enabling the loggers

JUseCase's loggers are enabled by setting the log level to INFO. To enable the e.g. setup log and redirect its output to the console, replace "log4j.logger.jusecase.setup = OFF, void" with "log4j.logger.jusecase.setup = INFO, stdout" in the log4j template provided above.