where's the System.out.println output or log4j console output?
I am invoking a simple helloworld Java class in SOATest using the Extension Tool. The method I'm running is behaving fine, except that I am unable to see the System.out or the log4j output (configured to output to console) from my Java class. I can see the output in console just fine when running the Java class outside of SOATest perspective.
I am currently using Application.showMessage("hello world"); to output to SOATest console, and that works fine.
I feel like i'm missing something obvious here. Please halp!
Answers
-
Your java class executes in the same JVM as SOAtest. To see messages printed to STDOUT/STDERR from the JVM, you can start the soatest exe with the -consolelog argument.
Concerning log4j, you can configure log4j to do what you want. Perhaps you want to configure a console appender, for example. Typically you configure things like appenders and log levels on a per-package basis. This could be done programmatically or from an external config file. Really, you would need to refer to the docs on apache.org for how to configure log4j.
Concerning Application.showMessage(String), this is the correct way to print messages to the SOAtest Console view in the workbench. Whether you want to print messages to the SOAtest Console view with Application.showMessage() or to STDOUT/STDERR with System.out/err is your choice.
0 -
I am able to configure log4j programmatically (as opposed to use the properties file). The code that sets up the log4j configs is located at the beginning of the method that is ran. This is a problem because I only need this code to run once, but it is running for each line of my datasource (causing inconsistent output). Is there a way to invoke a method once at the beginning of a test, then followed by the test iterations as determined by the datasource row?
Thanks,
0 -
A setup test is typically used for things that should only be done once. You can add an Extension Tool as a setup test as opposed to a normal test. However, whether you add it as a setup test or a normal test you probably want it added to the parent suite, not the suite that is looping over data source rows.
0 -
"you can start the soatest exe with the -consolelog argument"
I am able to see the java console output with the -console argument in my Windows shortcut "Target" field. Any idea how to append its output to a txt file?
0 -
To capture command line output from a process (SOAtest or otherwise) you can add something like
>log.txt 2>&1
to the end of the command. For example, this could besoatest -consolelog >log.txt 2>&1
. However, if you are on Windows (as opposed to Linux/Mac) this will only work if you start SOAtest the SOAtest UI with the eclipsec.exe (instead of soatest.exe) from the "Parasoft\Test\9.x" directory (for example, C:\Program Files\Parasoft\Test\9.10\eclipsec.exe).
Other explanation on the web:
https://www.eclipse.org/forums/index.php/t/104722/
http://www.eclipsezone.com/eclipse/forums/t101546.html
https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bashOtherwise, if you are doing a command line run with soatestcli, then soatestcli will show you all STDOUT/STDERR by default. If you are using a build automation tool to run soatestcli (Jenkins, Bamboo, TeamCity, etc.) then such tools generally archive the console output automatically.
0 -
What is System.out.println
System.out.println is a Java statement that prints the argument passed, into the System.out which is generally stdout.
System – is a final class in java.lang package. As per javadoc, “…Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array…“
out – is a static member field of System class and is of type PrintStream. Its access specifiers are public final. This gets instantiated during startup and gets mapped with standard output console of the host. This stream is open by itself immediately after its instantiation and ready to accept data.
println – is a method of PrintStream class. println prints the argument passed to the standard console and a newline. There are multiple println methods with different arguments (overloading). Every println makes a call to print method and adds a newline. print calls write() and the story goes on like that.
-1