Jetif: another choice for Java unit testing

Discussions

News: Jetif: another choice for Java unit testing

  1. Jetif: another choice for Java unit testing (17 messages)

    Jetif is an open source testing framework for Java programs. It is inspired by JUnit and JTestCase, and introduces some new functionality that aim to make it more powerful and flexible.

    Test data driven testing: test data can be separated from test code with Jetif. Jetif supports test data from various source in different format.

    Extendable Framework: Jetif provides more than one interfaces for users to extend their test easily, such as Handler and SpecProvider which allows user to customize their test tasks.

    Execution from CLI and ant task support, can be used for regression testing.

    The goal of the Jetif is to provides a simple but powerful testing framework for Java programs.

    Here's a comparision between Jetif and JUnit + JTestCase:
    http://jetif.sourceforge.net/docs/comparison.html

    Please visit http://jetif.sourceforge.net/ for more information.

    Threaded Messages (17)

  2. link to comparison doc[ Go to top ]

    Your comparison doc link is for chinese version. Better modify it to link to english version.
  3. There are two version of the page[ Go to top ]

    You will get Chinese version if your browser locale is zh_CN, and you can click the link to view the English version on the bottom of the page.
  4. You mean I could use XML files instead of re-writing the same test a dozen times to cover all the variants?

    This is one of those things I didn't even consider when using JUnit but now seems blantantly obvious. Next time I find myself writing Java code, I'll definitely be trying this out.

    --Jonathan
  5. Can't... resist... the... plug...
    You mean I could use XML files instead of re-writing the same test a dozen times to cover all the variants?This is one of those things I didn't even consider when using JUnit but now seems blantantly obvious. Next time I find myself writing Java code, I'll definitely be trying this out.--Jonathan

    That's the core principle of TestNG. You should be able to separate the static part (the code) from the runtime part of your tests (which tests are being run).

    However, I'm a bit surprised by how far JetiF goes in this area. If I didn't misunderstand, it's basically saying that instead of writing

    assertEquals(5, n);

    You should put the expected value 5 in an XML file. I'm not quite sure I see the point in that, because it's not very often that you will modify your XML file without having to modify your Java code as well.

    On the other hand, I'm completely on board with the idea of passing parameters to test methods (something that TestNG supports), but I guess I see these values as configuration parameters, and not expected test results.

    Different philosophies I guess.

    --
    Cedric
  6. Jetif is NOT a "killer"[ Go to top ]

    unlike the TestNG, the Jetif is not going to be a "killer", but only another choice.
    For what you doubt about, you can use assertEquals(5, n); in the code with some add-ons for Jetif. While it is not recommended by Jetif. The reason is the result "n" may be not consistant when the parameters changed. The expected result will always related with input parameters, and for same method, we can define "two" test method in test spec with different parameters and expected results. It's useful when you want test something with different data, for example, globalization testing.
    And, the Jetif allows you specify all data in the code if you don't like it, you can only return a boolean value or throw a exception or call the assert***() methods. It's up to you.
  7. The XML file is not required, but only an optional and recommended.
    We have support for JUnit support to run leagacy test code.
  8. Sorry, I had misunderstood what you said.
    The answer to your question is: Yes!
    You can create one method in code, which take some parameters. While you can define lots of test methods in XML file which reuse your method in Java code but with different test data and expected result.
    And the XML format is not the only choice in Jetif if you don't like it, you can specify test data in other format, for example, in a text file, or even in DBMS (not supported yet). The Jetif provides a extendable framework and such format can be supported if users wanted.

    Vicky Wang
  9. I just explored Jetif. So far its good.
    But one problem what I am facing is grouping some parameters like what JtestCase provides.

    Here's my scenario
    I have to pass an array of objects for a bean say customer.
    Class Customer
    {
    private int customerId;
    private int customerName;
    private String[] roles;
    private int[] productIds;
    // getters and setters for the above
    }

    If I want to pass 5 Customer Objects to my testmethod how can i achieve that.

    ex: Object-1: 100,Vicky,[Admin,user,default],[11,12,17,34]
        Object-2: 101,Nivas,[Admin,user],[56,43,34,66]
         :
         :
        Object-5:............

    Now I want to pass all these as an array of objects to my test method.

    How can i get all these to my handler so that I can create
    Array of Customer objects and pass it to my testMethod.

    Because the handler takes everything as a String when I write custom Handler.

    Is there anyway to group some parameters.

    Moreover there isn't any help doc for the spec file which talks in detail other than the spec file schema.

    ---Nivas

    Sorry, I had misunderstood what you said.The answer to your question is: Yes!You can create one method in code, which take some parameters. While you can define lots of test methods in XML file which reuse your method in Java code but with different test data and expected result.And the XML format is not the only choice in Jetif if you don't like it, you can specify test data in other format, for example, in a text file, or even in DBMS (not supported yet). The Jetif provides a extendable framework and such format can be supported if users wanted.Vicky Wang
  10. about the object array using the spec[ Go to top ]

    Hi Nivas
    Sorry for late reply because I haven't check messages on this thread few months.
    The current Jetif built-in array handler supports only the array for simple types (which mean the elements should be contructed from string). But the framework does allow you create custom handler to support any type of array you wanted. The issue you met might be there is no simple way to represents the complex data structure in the spec file. This is a limitation of current Jetif, and I think I can add support for complex data structure in the parameter spec, for example, you can specify a XML element as the parameter, and the Jetif will load it as DOM object and pass it to your handler. Then your handler will be able to convert it to the complex object you wanted.
    Sorry for the late reply, you point out an important issue, thank you very much.

    NOTE: please post your questions to the http://jetif.sourceforge.net/ and I will get notification if some new request been post.
  11. Jetif: another choice for Java unit testing[ Go to top ]

    anybody has experience with this framework?
  12. The homepage for Jetif[ Go to top ]

    Sorry, the homepage link is missed in original message.

    The homepage for Jetif is: http://jetif.sourceforge.net/
    For Chinese, you can visit the mirror in China: http://jtfhome.51.net/
  13. Hi there any budy knows about how Jetif is supported by diffrent IDE's like eclipse or Netbeans ?

    And if i decided to rewrite all Unit test cases again in to Jetif how is that ?
  14. The Jetif support that to run legacy JUnit test cases and it's unecessary to rewrite them. I'm strongly recommend that DON'T rewrite your legacy code except that you want to use the new features introduced by Jetif.

    There are several ways to move to Jetif:
    Solution A (no test code change):
    Just run your JUnit test cases with Jetif. for example:
    java -cp $CP jetif.ui.Console junit:YourJUnitSuiteClass
    There is no code change needed even re-compiling is not needed. But you need the junit.jar to run your test cases.

    Solution B (minor test code changes):
    If you don't like the junit.jar, there is an extension under developing which used to adapt JUnit test cases to Jetif. You'll only need to recompile your test code with that extension (hopes it can be such simple), and then you can run your test cases with only jetif. The only issue is that this extension is still under development. And you'll be able to use all features provided by Jetif with this extension.

    Solution C (many test code changes):
    If you don't like the junit.jar, don't want to wait the extension, you can change the test case class to be inherited from jetif.TestCase and change your test suite class to be inherited from jetif.Suite. You may have to add some assertXXX() method to TestCase class if you are using assertXXX() everywhere.

    Vicky Wang
  15. The plugin for eclipse is under developing, while there is no plan for other IDEs. Maybe you can do it, the Jetif is quite simple and I think it's not too hard to implement a UI/plugin.

    Vicky Wang
  16. This seems to me to be a promising new approach for java testing. By supporting a clean separation of concerns i can concentrate on what i really have to do: identify what will be tested (classes and methods) to be tested and write testcases (data).
    Anybody who has been wriiting any significant amount of testcases using Junit, knows how fast the test code itself can become "legacy" and how - more often then not - one is preoccupied by writting the testcode, rather then actually with testing.
    I hope the community will pick on this and be supportive ;-) I will certaintly give it try. In a way it reminds me of the Spring Framework has done in the J2EE area. We certainly could use some good alternatives in the Unit Testing area.
  17. Problem while coding in Jetif[ Go to top ]

    Hi Vicky,

    I am facing some problem while using Jetif. I just go throgh your article where you mentioned about the advantages of using Jetif over Junit.
    Suppose I have 2 Java files
    1. Utility.java - Main Class
    2. UtilityTest.java - Containg test classes of Utility.java


    Utility.java
    public int squareValue(int x){
    return x*x;
    }

    UtilityTest.java

    Utility objUtil = null;

    protected boolean setup() {
    System.out.println("setup is called.");
    objUtil = new Utility();
    return true;
    }

    protected void cleanup(boolean flag) {
    objUtil = null;
    System.out.println("cleanup is called with flag: " + flag);
    }
    public void testsquareValue(int input) {

    //int ret = input;
    int ret = objUtil.squareValue(input);
    assertTrue(ret==8);
    // assertTrue(ret==4);
    // assertTrue(ret==9);
    System.out.println("test caseq : "+ret);

    }

    Utility.spec

    <?xml version="1.0" encoding="UTF-8"?>
    <suite name="utility" class="com.TestCase.UtilitySuite">

    <testcase name="Test Case1">
    <method name="testsquareValue">
    <param>1</param>
    <expected>2</expected>
    </method>
    </testcase>

    <testcase name="Test Case2">
    <method name="testsquareValue">
    <param>2</param>
    <expected>4</expected>
    </method>
    </testcase>

    <testcase name="Test Case3">
    <method name="testsquareValue">
    <param>3</param>
    <expected>9</expected>
    </method>
    </testcase>



    </suite>

    The problem I am facing is how to test the expected value from the spec file with the actual value.
    How to do same using assertTrue()
    Since Jetif has no assertXXX() function, so how do I proceed further as I want to retreive the value from the spec file in the UtilityTest.java.

    Kindly give me the code in above scenario as I want my test shoould fail in first test case however pass in another testcases.

    Do reply at the earliest.
    Regards
    Nitin
    (nitinsarna2000 at yahoo dot com)
  18. Please post question to the project[ Go to top ]

    Sorry, I'm not monitoring this thread, so won't reply in time if you post any question here.
    For bug and feature request, please post to
    http://sourceforge.net/tracker/?group_id=125864
    For question, please post to
    http://sourceforge.net/forum/?group_id=125864