Loading ...
Sorry, an error occurred while loading the content.

Re: [junit] SetMock in Junit..

Expand Messages
  • Lasse Koskela
    ... You could look into whether JEasyTest would do the trick for you: https://jeasytest.dev.java.net It does require AspectJ and I haven t tried JEasyTest
    Message 1 of 4 , Nov 1, 2007
    View Source
    • 0 Attachment
      On 11/1/07, aashish <aashish_tau17@...> wrote:
      > Please assist me in mocking a static function of the source code in the
      > testing code, when I cannot change the source code....

      You could look into whether JEasyTest would do the trick for you:

      https://jeasytest.dev.java.net

      It does require AspectJ and I haven't tried JEasyTest myself but they
      should be able to "redirect" static method calls to an alternative
      implementation.

      Lasse

      --
      Lasse Koskela
      * Author of "Test Driven" (Manning Publications, 2007) *
      * Reaktor Innovations * http://www.ri.fi/en *
    • Paul King
      ... If you have the ability to use dynamic languages, you can certainly do this in Groovy and I would imagine Ruby (not sure). Otherwise, you might want to
      Message 2 of 4 , Nov 1, 2007
      View Source
      • 0 Attachment
        aashish wrote:
        > Please assist me in mocking a static function of the source code in the
        > testing code, when I cannot change the source code....

        If you have the ability to use dynamic languages, you can certainly
        do this in Groovy and I would imagine Ruby (not sure). Otherwise,
        you might want to consider JMockit (https://jmockit.dev.java.net/)
        if you have the ability to run your tests on a Java 5 or 6 JVM.

        Paul.

        > --
        > View this message in context:
        > http://www.nabble.com/SetMock-in-Junit..-tf4729425.html#a13523500
        > <http://www.nabble.com/SetMock-in-Junit..-tf4729425.html#a13523500>
        > Sent from the JUnit - User mailing list archive at Nabble.com.
      • James Abley
        ... If it s just a method that your code is calling, you could wrap it in a simple Command interface and supply an implementation in your tests that does what
        Message 3 of 4 , Nov 1, 2007
        View Source
        • 0 Attachment
          On 01/11/2007, Paul King <paulk@...> wrote:
          >
          > aashish wrote:
          > > Please assist me in mocking a static function of the source code in the
          > > testing code, when I cannot change the source code....
          >
          > If you have the ability to use dynamic languages, you can certainly
          > do this in Groovy and I would imagine Ruby (not sure). Otherwise,
          > you might want to consider JMockit (https://jmockit.dev.java.net/)
          > if you have the ability to run your tests on a Java 5 or 6 JVM.
          >
          > Paul.
          >

          If it's just a method that your code is calling, you could wrap it in
          a simple Command interface and supply an implementation in your tests
          that does what you want. If it's a method that's buried a little
          deeper, then your workaround will get a little more complex. Lasse has
          already suggested an AspectJ-based solution and I would second that
          suggestion.

          Cheers,

          James
        Your message has been successfully submitted and would be delivered to recipients shortly.