Menu

logging problem

Anonymous
2004-07-16
2004-07-27
  • Anonymous

    Anonymous - 2004-07-16

    hi,

    I have just started using sqlunit and ant recently. I am finding trouble logging the results of my tests to files. Firstly there is a warning that log4j has not been properly initialized though I have copied the log4j properties file into the jar archive of log4j.1.2.8 in my classpath.

    Secondly the sqlunit output comes out fine on the console, or in a file specified as as argument to ant but when I specify a logfile within the sqlunit task the output is slightly jumbled with some control characters in there.

    CONSOLE Output:
    def:

    mrs_sp_web_lim_hdr_get:

      [sqlunit] log4j:WARN No appenders could be found for logger (net.sourceforge.sqlunit.SQLUnit).
      [sqlunit] log4j:WARN Please initialize the log4j system properly.
      [sqlunit] *** Running SQLUnit file: u:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml
      [sqlunit] Getting connection(DEFAULT)
      [sqlunit] Setting up test...
      [sqlunit] Running test[1]: Checking it (656ms)
      [sqlunit] No match on variable at [rset,row,col]=([1,1,5]
      [sqlunit] *** expected:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">2256</col>
      [sqlunit]       <col id="2" type="INTEGER">2256</col>
      [sqlunit]       <col id="3" type="NUMERIC">333</col>
      [sqlunit]       <col id="4" type="CHAR">R       </col>
      [sqlunit]       <col id="5" type="SMALLINT">0</col>
      [sqlunit]       <col id="6" type="VARCHAR">Other Regional</col>
      [sqlunit]       <col id="7" type="VARCHAR">11 Apr 2002</col>
      [sqlunit]       <col id="8" type="VARCHAR">11 Apr 2002</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>
      [sqlunit] *** but got:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">2256</col>
      [sqlunit]       <col id="2" type="INTEGER">2256</col>
      [sqlunit]       <col id="3" type="NUMERIC">333</col>
      [sqlunit]       <col id="4" type="CHAR">R       </col>
      [sqlunit]       <col id="5" type="SMALLINT">9</col>
      [sqlunit]       <col id="6" type="VARCHAR">Other Regional</col>
      [sqlunit]       <col id="7" type="VARCHAR">11 Apr 2002</col>
      [sqlunit]       <col id="8" type="VARCHAR">11 Apr 2002</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>

      [sqlunit] Tearing down test...
      [sqlunit] SQLUnit Tests Failed: In file: u:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
      [sqlunit] One or more SQLUnit Tests failed, see the console for details

    BUILD SUCCESSFUL
    Total time: 7 seconds

    LOGFILE Output:
    *** Running SQLUnit file: u:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml
    Getting connection(DEFAULT)
    Setting up test...
    Running test[1]: Checking it (141  [sqlunit] SQLUnit Tests Failed: In file: u:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
    pe="INTEGER">2256</col>
          <col id="2" type="INTEGER">2256</col>
          <col id="3" type="NUMERIC">333</col>
          <col id="4" type="CHAR">R       </col>
          <col id="5" type="SMALLINT">0</col>
          <col id="6" type="VARCHAR">Other Regional</col>
          <col id="7" type="VARCHAR">11 Apr 2002</col>
          <col id="8" type="VARCHAR">11 Apr 2002</col>
        </row>
      </resultset>
    </result>
    *** but got:
    <result>
      <resultset id="1">
        <row id="1">
          <col id="1" type="INTEGER">2256</col>
          <col id="2" type="INTEGER">2256</col>
          <col id="3" type="NUMERIC">333</col>
          <col id="4" type="CHAR">R       </col>
          <col id="5" type="SMALLINT">9</col>
          <col id="6" type="VARCHAR">Other Regional</col>
          <col id="7" type="VARCHAR">11 Apr 2002</col>
          <col id="8" type="VARCHAR">11 Apr 2002</col>
        </row>
      </resultset>
    </result>

    Tearing down test...

    Please let me know what I am doing wrong here.

    Thanks,
    Omer

     
    • Sujit Pal

      Sujit Pal - 2004-07-16

      Hi Omer,

      It may be a classpath issue, since there is already a log4j jar file in the distribution, and if you are using the supplied ant build.xml file to call it, it loads your classpath after its own. In that case, try removing or renaming the log4j.jar file in the lib/ subdirectory of the distribution and see if the error goes away.

      I have been including third-party jars along with SQLUnit as a convenience, since I personally prefer my package in a single download. Basically, anything that is not sqlunit-${version}.jar in the lib/ directory of the distribution is an external jar, and if you already have it in your classpath, feel free to remove it.

      -sujit

       
    • Anonymous

      Anonymous - 2004-07-22

      Hi sujit,

      thanks, but its probably not a class path issue cause the log4j jar file in the sqlunit lib directory is currently the only log4j jar file in my classpath... if I rename it then sqlunit gives the following error probably because it cant fine log4j jar anymore:

      mrs_sp_web_lim_hdr_get_test:
        [sqlunit] org/apache/log4j/Logger

      there is a log4j properties file in the sqlunit docs directory. do i need to put this file somewhere particular for log4j to run properly? as the warning message i posted above shows that it cant find appender for sqlunit which has been defined in the properties file.

      -omer

       
    • David Fishburn

      David Fishburn - 2004-07-22

      I can't remember what my initial problem was now, but I do remember I had to upgrade to the latest version of ANT to get sqlunit to work correctly.

      I believe I had 1.5.? installed and had to upgrade to 1.6.1.

      Just thought I would offer that to cross check.

      Dave

       
    • Anonymous

      Anonymous - 2004-07-22

      thanks dave. my ant is 1.6.1. I have put the log4j.properties file in the log4j jar file at top level and now it does apparently read it however I get the following output on the console:

      [sqlunit] *** Running SQLUnit file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml
      [sqlunit] Getting connection(DEFAULT)
      [sqlunit] Setting up test...
      [sqlunit] Running test[1]: Sample test (79ms)
      [sqlunit] No match on variable at [rset,row,col]=([1,1,1]
      [sqlunit] *** expected:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">16</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>
      [sqlunit] *** but got:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">160</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>

      [sqlunit] Running test[2]: Sample test2 (32ms)
      [sqlunit] No match on variable at [rset,row,col]=([1,1,1]
      [sqlunit] *** expected:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">16</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>
      [sqlunit] *** but got:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">160</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>

      [sqlunit] Tearing down test...
      [sqlunit] FATAL [main] (SQLUnit.java:149) - SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 2, failures: 1, errors = 0
      [sqlunit] net.sourceforge.sqlunit.SQLUnitException: SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 2, failures: 1, errors = 0
      [sqlunit]     at net.sourceforge.sqlunit.SQLUnit.testWrapper(SQLUnit.java:174)
      [sqlunit]     at net.sourceforge.sqlunit.SQLUnit.runTest(SQLUnit.java:147)
      [sqlunit]     at net.sourceforge.antsqlunittask.SqlunitTask.execute(SqlunitTask.java:109)
      [sqlunit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
      [sqlunit]     at org.apache.tools.ant.Task.perform(Task.java:364)
      [sqlunit]     at org.apache.tools.ant.Target.execute(Target.java:301)
      [sqlunit]     at org.apache.tools.ant.Target.performTasks(Target.java:328)
      [sqlunit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
      [sqlunit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
      [sqlunit]     at org.apache.tools.ant.Main.runBuild(Main.java:632)
      [sqlunit]     at org.apache.tools.ant.Main.startAnt(Main.java:183)
      [sqlunit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
      [sqlunit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
      [sqlunit] SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 2, failures: 1, errors = 0
      [sqlunit] One or more SQLUnit Tests failed, see the console for details

      no warnings given for initializing log4j BUT when I put the logfile in the sqlunit task file the reportfile just contains the text starting "[sqlunit] FATAL [main] (SQLUnit.java:149) - SQLUnit Tests Failed: In file: ... ". And nothing before that.

      the log4j.properties file that i am using is:
      # Create a single console appender that logs INFO and higher
      log4j.rootLogger = DEBUG,sqlunit

      # Configure stdout appenders to go to console
      log4j.appender.sqlunit = org.apache.log4j.ConsoleAppender

      # Configure stdout appender to use PatternLayout
      log4j.appender.sqlunit.layout = org.apache.log4j.PatternLayout

      # Pattern to output the caller's file name and line number
      log4j.appender.sqlunit.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

      -omer.

       
    • Sujit Pal

      Sujit Pal - 2004-07-22

      Hi Omer,

      SQLUnit does need its own log4j.properties file, and it should be in the classpath. This is to make the debug attribute in the sqlunit task work. There was a bug opened few releases ago, that said that putting the log4j.properties in the distribution root was a bad thing and the way I was reading the properties file was flimsy, so I changed it to be a resource that needs to live in the classpath and put it in the doc/ directory, and added the doc directory to my classpath in the build.xml so I could still work with it the way I did before.

      I have not tested what would happen if upi have another log4j.properties file. If it doesnt have a log4j.properties file, it will complain with a message and not do any logging.

      If you specify the logfile attribute in the sqlunit task, it will redirect what it printed to the console to the logfile, and tell you that it did so on the console (ie the last line of output). From your test reports above, it looks like you were specifying two tests which failed. What is in your logfile? Does it only contain the string you mentioned? If so, this looks like a bug introduced when we did the configurable reporters option. Let me know if thats what you are seeing and I will fix it.

      Not sure about the ant version, I think I am using ant 1.5 but I could be wrong, I will check and update this thread (and the documentation) with that information.

      Thanks
      -sujit

       
    • Anonymous

      Anonymous - 2004-07-23

      I can't seem to get log4j to work withuot putting the log4j.properties file in the jar file. anyway since the log4j initialization warning goes away by doing that and it starts showing the exceptions, I will do with that for now. how and where in the buildfile do you specify the path for the docs dir?

      for one test that fails the output in the logfile if I specify one for the test is:

        [sqlunit] FATAL [main] (SQLUnit.java:149) - SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
        [sqlunit] net.sourceforge.sqlunit.SQLUnitException: SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
        [sqlunit]     at net.sourceforge.sqlunit.SQLUnit.testWrapper(SQLUnit.java:174)
        [sqlunit]     at net.sourceforge.sqlunit.SQLUnit.runTest(SQLUnit.java:147)
        [sqlunit]     at net.sourceforge.antsqlunittask.SqlunitTask.execute(SqlunitTask.java:109)
        [sqlunit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
        [sqlunit]     at org.apache.tools.ant.Task.perform(Task.java:364)
        [sqlunit]     at org.apache.tools.ant.Target.execute(Target.java:301)
        [sqlunit]     at org.apache.tools.ant.Target.performTasks(Target.java:328)
        [sqlunit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
        [sqlunit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
        [sqlunit]     at org.apache.tools.ant.Main.runBuild(Main.java:632)
        [sqlunit]     at org.apache.tools.ant.Main.startAnt(Main.java:183)
        [sqlunit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
        [sqlunit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
        [sqlunit] SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0

      the output on the console if I dont specify the logfile is:

      [sqlunit] *** Running SQLUnit file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml
      [sqlunit] Getting connection(DEFAULT)
      [sqlunit] Setting up test...
      [sqlunit] Running test[1]: Sample test (94ms)
      [sqlunit] No match on variable at [rset,row,col]=([1,1,1]
      [sqlunit] *** expected:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">16</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>
      [sqlunit] *** but got:
      [sqlunit] <result>
      [sqlunit]   <resultset id="1">
      [sqlunit]     <row id="1">
      [sqlunit]       <col id="1" type="INTEGER">160</col>
      [sqlunit]     </row>
      [sqlunit]   </resultset>
      [sqlunit] </result>

      [sqlunit] Tearing down test...
      [sqlunit] FATAL [main] (SQLUnit.java:149) - SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
      [sqlunit] net.sourceforge.sqlunit.SQLUnitException: SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
      [sqlunit]     at net.sourceforge.sqlunit.SQLUnit.testWrapper(SQLUnit.java:174)
      [sqlunit]     at net.sourceforge.sqlunit.SQLUnit.runTest(SQLUnit.java:147)
      [sqlunit]     at net.sourceforge.antsqlunittask.SqlunitTask.execute(SqlunitTask.java:109)
      [sqlunit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
      [sqlunit]     at org.apache.tools.ant.Task.perform(Task.java:364)
      [sqlunit]     at org.apache.tools.ant.Target.execute(Target.java:301)
      [sqlunit]     at org.apache.tools.ant.Target.performTasks(Target.java:328)
      [sqlunit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
      [sqlunit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
      [sqlunit]     at org.apache.tools.ant.Main.runBuild(Main.java:632)
      [sqlunit]     at org.apache.tools.ant.Main.startAnt(Main.java:183)
      [sqlunit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
      [sqlunit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
      [sqlunit] SQLUnit Tests Failed: In file: U:\TestEnv\Framework\test\mrs_sp_web_lim_hdr_get_test.xml, tests: 1, failures: 1, errors = 0
      [sqlunit] One or more SQLUnit Tests failed, see the console for details

      Thanks,
      Omer

       
    • Sujit Pal

      Sujit Pal - 2004-07-27

      Just FYI, I am using ant 1.6.0 in my distribution. It does not look like an ant problem though. It /does/ need 1.6+ for javadocs.

      I still have to look at why the logfile attribute is misbehaving, I will do it soon and update this thread.

      The docs dir is specified in the init target as ${doc.dir}.

      -sujit

       

Log in to post a comment.