Writing to file in JUnit test case? Not working?

I have a singleton class called InstantLogger that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
When I use this class outside of the JUnit test suite it works fine.
As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?
Thanks,

avalanche333 wrote:
I have a singleton class called InstantLogger Ouch.
that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
When I use this class outside of the JUnit test suite it works fine.Oh, brother.
>
As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?Um, no.
Your code is wrong. You're assuming something that isn't correct. You're also making the assumption that just because it "works" in another context that it's right in all contexts. The two aren't the same, be it configuration or something else.
Singleton? That GoF pattern has been voted off the island. Didn't you hear?
http://code.google.com/p/google-singleton-detector/
%

Similar Messages

  • Exception while running a test file as JUNIT test case

    Hi,
    I am trying to build a code using Eclipse to generate an "ear" file that can be used for deployment. The ear file is generated successfully but the build is not successful as the following exception is thrown while debugging a junit test case:
    javax.naming.CommunicationException: tdk.dk:389 [Root exception is java.net.SocketTimeoutException: connect timed out]
         at com.sun.jndi.ldap.Connection.<init>(Connection.java:197)
         at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
         at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1580)
         at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2616)
         at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:287)
         at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
         at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
         at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
         at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at junit.framework.TestCase.runTest(TestCase.java:154)
         at junit.framework.TestCase.runBare(TestCase.java:127)
         at junit.framework.TestResult$1.protect(TestResult.java:106)
         at junit.framework.TestResult.runProtected(TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:118)
         at junit.framework.TestSuite.runTest(TestSuite.java:208)
         at junit.framework.TestSuite.run(TestSuite.java:203)
         at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Kindly suggest a solution.
    P.S. : All test cases are running fine except for one test case, whose error details are given.

    No it is not. The Oracle JDeveloper and ADF forum is for development questions around development with Oracle JDeveloper and ADF.
    If you use Eclipse through OEPE, you could post the question here
    Enterprise Pack for Eclipse
    If you don't use OEPE but Eclipse, then this forum may be a great source of help: http://stackoverflow.com/
    Frank

  • War file deployment to Test env not working

    Hi All,
    i am using war file as scheduler for calling bpel process. Now i need to move the same war to test environment. For this i followed this site http://biemond.blogspot.ca/2009/04/using-weblogic-deployment-plan-to.html. But it is not working.
    even i update the generated deployment plan to weblogic console, but still this is not working.
    here is the my web.xml file
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
      <description>Empty web.xml file for Web Application</description>
        <context-param> 
            <param-name>wsdlUrl</param-name> 
            <param-value>http://sasoah91.corp.gdglobal.ca:8001/soa-infra/services/TarakTest/TSStoRMSScheduler/tsstormsschedulerproject_client_ep?WSDL</param-value> 
         </context-param>
      <servlet>
        <servlet-name>SOASchedulerServlet</servlet-name>
        <servlet-class>sample.oracle.otn.soascheduler.SOASchedulerServlet</servlet-class>
         <init-param>
          <param-name>cronExpr</param-name>
          <param-value>0 0,5,10,15,20,25,30,35,40,45,50,55 * * * ?</param-value>
        </init-param>
      </servlet>
      <servlet-mapping>
        <servlet-name>SOASchedulerServlet</servlet-name>
        <url-pattern>/soaschedulerservlet</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>/soaschedulerservlet</welcome-file>
      </welcome-file-list>
    </web-app>My deployment plan is
    <?xml version='1.0' encoding='UTF-8'?>
    <deployment-plan xmlns="http://xmlns.oracle.com/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd" global-variables="false">
      <application-name>TSSScheduler.war</application-name>
      <variable-definition>
      <!--  add the wsdl var   -->
        <variable>
            <name>wsdlUrl</name>
            <value>http://sasoah81.corp.gdglobal.ca:8001/soa-infra/services/TSStoRMS/TSStoRMSScheduler/tsstormsschedulerproject_client_ep?WSDL/</value>
         </variable>
        </variable-definition>
      <module-override>
        <module-name>TSSScheduler.war</module-name>
        <module-type>war</module-type>
        <module-descriptor external="false">
          <root-element>weblogic-web-app</root-element>
          <uri>WEB-INF/web.xml</uri>
              <variable-assignment>
             <name>wsdlUrl</name>
             <xpath>/web-app/context-param/[param-name="wsdlUrl"]/param-value</xpath>
             <operation>replace</operation>
           </variable-assignment>
          </module-descriptor>
      </module-override>
      <!--<config-root>/u01/textdata/SOATST/Tarak/TsstoRmsSchedulerProject/deploy</config-root>-->
    <config-root>/u01/textdata/SOATST/Tarak/deploymentplan</config-root>
    </deployment-plan>I ran below code
    export ORACLE_HOME="/u01/app/soadev/product/fmw11/middleware"
    echo "ORACLE_HOME=$ORACLE_HOME"
    ls -l $MW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh
    . $MW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh
    export JAVA_HOME="/usr/java/jdk1.6.0_24"
    export planname="TSSScheduler.xml"
    export warfile="/u01/textdata/SOATST/Tarak/TsstoRmsSchedulerProject/deploy/TSSScheduler.war"
    echo "---------------------------------------"
    echo "THE CLASSPATH=$CLASSPATH"
    echo "---------------------------------------"
    java weblogic.Deployer -adminurl t3://sasoah81.corp.gdglobal.ca:7001 -username weblogic -password Soatst_s132 -deploy -name TsstoRmsSchedulerProject -source $warfile -targets AdminServer -stage -plan $plannameCan some one please let me know where i am going...
    Also can some one tell me any other way to change the endpoint in war file. this is very urgent so kindly request all to let me know how to go with it.
    Regards,
    Tarak.

    Hi,
    Here is what the parameter says
    <servlet>
    <servlet-name>SOASchedulerServlet</servlet-name>===================My Serverlet name
    <servlet-class>sample.oracle.otn.soascheduler.SOASchedulerServlet</servlet-class>======Server class
    <init-param>
    <param-name>cronExpr</param-name>=======this is cron job
    <param-value>0 0,5,10,15,20,25,30,35,40,45,50,55 * * * ?</param-value>===this invoke my bpel process in every 5 mins.
    </init-param>
    </servlet>
    Please see the side line comments
    Sure i will open the ticket,
    Regards,
    Tarak.

  • Getting error while writing JUnit test case for RestFul Services

    Hi All,
    I have written Restful services in Netbean 6.8.
    It's running well...no issues.
    {color:#0000ff}While writing JUnit test cases for them, I am getting following error:
    {color}{color:#993300}Testcase: testGetAuthenticated(com.ct.services.LoginServicesTest): Caused an ERROR
    Implementing class{color}
    java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:160)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:65)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    at com.ct.services.LoginServices.getAuthenticated(LoginServices.java:205)
    at com.ct.services.LoginServicesTest.testGetAuthenticated(LoginServicesTest.java:84)
    Test com.ct.services.LoginServicesTest FAILED
    F:\NetbeanProjectsWorkspace\DemoProject\nbproject\build-impl.xml:972: Some tests failed; see details above.
    BUILD FAILED (total time: 11 seconds)
    {color:#0000ff}Strange thing is that when I am commenting below lines and its related calls:
    {color}
    {color:#ff0000}EntityManagerFactory mEmf = Persistence.createEntityManagerFactory("AnyName");
    EntityManager mEm = mEmf.createEntityManager();
    {color}
    {color:#0000ff}from my code, JUnit test cases are working fine.
    {color}Anybody having any idea about this ?
    Thanks
    Avi
    Edited by: Avi007 on Aug 28, 2010 5:17 AM

    Hi All,
    [http://stackoverflow.com/questions/2778295/test-driven-development-problem]
    Please refer the above link for the solution
    Thanks
    Avi
    Edited by: Avi007 on Aug 30, 2010 12:33 AM

  • Creating junit test cases using the reflection API

    In order to use the reflection API to get information about a *.java file's class name and methods, I need to compile the *.java file first, and then get info through the *.class file. Am I right?
    Eclipse, the Java IDE, can create junit test cases for java files the user selects right after the *.java files have been created, and even before the *.java files have been compiled by the user. I guess Eclipse internally compiles the java files before creating JUnit test cases for them. Does anyone know about it? Thanks.

    Let me explain my problem in more details.
    Given any java source tree, my program is supposed to create junit test cases for each class using java reflection. My approach is to scan through the source tree to keep the list of classes available, then compile all the java files in the given source tree, then do Class.forName() to load them to get their methods... Obviously I don't know what classes I will have at compilation time. I create a temp_classes directory as the output directory for the given source tree java files, and I add temp_classes to my classpath when I strart up my own program. However, that won't work..
    D:\eclipse\workspace\cmpe271_hw4\classes>java -classpath ..\classes;..\temp_classes Test
    javac -classpath .\temp_classes; -d .\temp_classes @temp_classes\javalist.txt
    java.lang.ClassNotFoundException: Factory
    java.lang.ClassNotFoundException: InvalidDateFormatException
    java.lang.ClassNotFoundException: MyUtility
    java.lang.ClassNotFoundException: Storage

  • Executing Junit test case in EM console

    Hi ,
    When i execute Junit test case in EM console, and against the tab test runs my assertion details gets failed and data in both column, expected value and actual value remains the same but in the expected value column the name space gets automitically populated. Am not able to include the namespace in Junit test case as it gets removed at the run time .
    Kindly suggest.

    Were you able to solve this issue ?

  • [svn:bz-trunk] 13744: Bug: BLZ-481 - AMFConnection JUnit test do not run properly as part of checkintests on Mac  (and Windows?)

    Revision: 13744
    Revision: 13744
    Author:   [email protected]
    Date:     2010-01-25 01:14:09 -0800 (Mon, 25 Jan 2010)
    Log Message:
    Bug: BLZ-481 - AMFConnection JUnit test do not run properly as part of checkintests on Mac (and Windows?)
    QA: No
    Doc: No
    Checkintests: Pass
    Details:
    -Don't start the server before unit task, unit task already checks if the server is not running and starts the server.
    -Don't stop the server after FlexUnit tests, JUnit tests need the server running, and they will stop the server after they are done.
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-481
    Modified Paths:
        blazeds/trunk/build.xml
        blazeds/trunk/qa/apps/qa-regress/testsuites/flexunit/build.xml

    Tony,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Do a search of our knowledgebase at http://support.novell.com/search/kb_index.jsp
    - Check all of the other support tools and options available at
    http://support.novell.com.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://support.novell.com/forums)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://support.novell.com/forums/faq_general.html
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • Junit test cases

    hi friends,
    I am new to junit, so please tell me how to write junit test cases for static as well as for the method which return void. and also give any sample example which return void and declaring as static.
    please friends i need your help.
    Thank you

    Lekha28 wrote:
    I am new to junit, so please tell me how to write junit test cases for static...Testing a static method is the same as testing a non-static method. You decide what you are going to test, you set up the appropriate conditions, call the method and assert that the results match your expectations.
    as well as for the method which return void. See above. There must be something you can assert about the results of the method. If you can't, then you'll need to consider refactoring your class so that it is easier to test (or accept that there is nothing to test, and therefore no need for the method).
    ~

  • Conext Sensitive Help Test Tool Not Working

    I have been trying to test my map files with the context-sensitive test tool, but am unable to get it working. I am running TCS 3.5 on Windows XP Pro.
    I created a map files for Java in the project file and then created several test links with Map IDs. I am working with an offline WebHelp system on my C drive. I open the CSH Test Tool and located the index_csh.htm file for the WebHelp help system and then choose the Map Number. But when I click "Show Help," nothing appears. The hourglass comes up for a brief instant, as if it's going to load the page, but then nothing happens.
    Can anyone help?
    Thanks in advance.
    Douglas

    Hi, William:
    Your C# API allowed me to successfully test. Thanks.
    However, I was reading a bit more of the information on your site, and am still unclear why the deafult RH CSH Tester would not work. I was only using map numbers. Very frustrating.
    I also had a few other questions, since this is the first time I'm creating a mapping file in RH:
    - Is there any way to batch test? Or, if the icons appear blue (indicating they are correctly linked) in the Edit Map IDs dialogue box, can I just use your C# API to test a few and assume that they others are also working?
    - Is this API set to open up the pages in IE by default? Mine is doing that, but I wasn't sure if it was your app or my computer settings. I'm in an corporate environment where we are supposed to use IE as the default browser, although I have FF installed, too. It keeps opening an IE window with a security message that says JavaScript is not supported and I have to click the bar at the top to allow ActiveX controls to work. I'm pretty sure that last part is a security setting I can't change here, but not so sure about the default browser choice.
    -I haven't downloaded your API testers in other languages. Are they all the same with the difference just being language preference for the person testing it, or do some of them offer more functionality?
    Thanks for sharing your great tool!
    Douglas

  • Why while in Bridge Load Files into photoshop Layers does not work?

    In Bridge, Tools>Photoshop>Load Files into Photoshop Layers does not work.  I have two images selected and when I execute that comman in Bridge nothing happens.  I exited and restarted both PS and Bridge and still nothing.  I am working in Windows 7 and Photoshop cs6.

    No I tried File/scripts/load file into stack and still did not work.
    There was an update to bridge and now it works.  Thanks so much.

  • Power book G4 Leopard 10.5.8. File sharing preference checked but not working after start up until unchecked and the rechecked?

    I hope the title is enough info, please ask. In the mean time I have created an applescript to open preferences/ sharing and uncheck then check the file sharing box. This works but I would obviously prefer it just work normally. I have no corrupt preference files. Perhaps a file is missing? Thank you.

    Greetings Kwnez
    I'm not up to your level of expertise yet. I'm networking and file sharing too, on my Mac Powerbook 1.33 GHz PowerPC G4; OS 10.5.8 Lepoard. At the public library I found by asking the clerk a book Authored by David Pogue. "Mac OS X Leopard the Missing Manual". It (the book) has helped me ask better questions. I'm not saying that your question "
    Power book G4 Leopard 10.5.8. File sharing preference checked but not working after start up until unchecked and the rechecked?
    is hard for me to understand, I went to system preferences and looked at the sharing box. when I clik it it opens up and the first thing I see is my computers name, and under that i see, " Computers on your local network can access your computer at: ...-powerbook-g4-15.local"
    What I'm saying is "Are we on the same Page"

  • Smart case not working. Ipad Air 2 8.1.3

    Hi,
    I just bought a new smart case for Ipad Air 2. I notice that the case not working (open,close cover nothing happens). General setting doesn't have the turn on/off (or lock/unlock or smt like that) under auto lock settings. Anyone has the solution ?
    Thanks

    Thanks SergZak  JimHdk
    I will bring my stuffs to the Apple store and tell them to check. However, is there any chance that problem caused by a screen protector ?! I also bought one that made by shatter resistant glass and that's thicker than other. May be that reduce the sensor sensibility?   

  • Test sequences not working in standard prototype adaptor with Execute Steps in process

    Test sequences not working in standard prototype adaptor with "Execute Steps in process" but the sequences works in "Execute steps in an External instance of CVI"(Debug mode). Pl help with solution
    Apriciate your help
    Regards,
    Sharanu

    Sharanu,
    Thanks for contacting National Instruments. It would help us out a lot if you could specify exactly what is not working. Will the sequence just not run? Is it giving you an error message? Or what exactly does not work about it? The initial thing that I could think of that would make it not work in External Instance but not using the RunTime Engine is that you might be missing a support library when trying to run it in this configuration. If you click on the "Configure Auto-Loading of Support Libraries Needed for Linking .objs and .libs" button, you can make sure that all the support libraries you might be using are added in this list (you can add them using the "Add Other Libraries..." button). If this does not fix your problem, then let us know a litt
    le more about what is going on and we can help you from there. Thanks.
    Adam B.
    Applications Engineer
    National Instruments

  • JDev 10.1.2 - JUnit Extension Does not work

    When migrating from JDev 9.0.5.2 to 10.1.2 I get an error on startup the indicates that the JUnit extension is not working:
    Error: &lt;Line 2, Column 71&gt;: XML-24538: (Error) Can not find definition for element 'extensions'
    Converting JDeveloper 9.0.5 extension manifest to 10.1.2
    C:\Oracle\JDev\jdev\lib\ext\jalopy-jdeveloper-1.1.4.jar!\META-INF\jdev-ext.xml
    Error: &lt;Line 3, Column 21&gt;: XML-24534: (Error) Element 'feature' not expected.
    Error: &lt;Line 11, Column 14&gt;: XML-24521: (Error) Element not completed: 'extensions'
    C:\Oracle\JDev\jdev\lib\ext\bc4j_junit_addin.jar!\meta-inf\jdev-ext.xml
    Error: &lt;Line 3, Column 21&gt;: XML-24534: (Error) Element 'feature' not expected.
    Error: &lt;Line 22, Column 14&gt;: XML-24521: (Error) Element not completed: 'extensions'

    I am actually working with JDev10.1.2 and I recently created a new Extension. Since then, when I load jdev I get the error
    "C:\oracle10bis\jdev\lib\ext\DBExtension.jar!\meta-inf\jdev-ext.xml
    Error: <Line 2, Column 71>: XML-24538: (Error) Can not find definition for element 'extensions'
    Converting JDeveloper 9.0.5 extension manifest to 10.1.2"
    I followed your advice, downloaded and installed the JUnit component, but the error is still present. Moreover, if i try using the "Check for updates" functionality, I always get:
    "Unable to connect to OTN
    Details: Connection timeout: connect"
    Any ideas?
    Thanks in advance

  • PS CS3 not recognizing Raw Files and converters Ive downloaded not working..Why not?

    PS CS3 not recognizing Raw Files and converters Ive downloaded not working..Why not?

    Do you seriously think we can answer that with zero information from you?
    Please give us:
    Operating System/version
    Photoshop version number
    Amount of RAM installed
    Hard drive(s) free capacity
    Video card make and model
    Camera make and model
    Then describe what you have done so far and the symptoms you are seeing.

Maybe you are looking for