Skip to main content

JavaTest code generation tools available?

1 reply [Last post]
evgeny4
Offline
Joined: 2006-06-28
Points: 0

As mentioned in Alexey's blog, making assertions in JavaTest is different from JUnit. And that's annoying when dealing with quality testing.

On the other hand, it's obvious that assert(msg, expr) could be easily replaced by if (!expr) return Status.failed(msg); and I guess there should be some tools for making this automatically.

So I wander if there any recommendations or best-practices for tests sources' format and tools for test java code generation?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexeyp
Offline
Joined: 2006-10-04
Points: 0

Hi Evgeny

if we are talking about the task of using JT harness and ME Framework for test execution and Unit-like format for test development, there are several existing approaches here.

1. simulate assert-stype API with some adapter. In some test suites people use MultiTest extensions with additional 'assert' API, it is possible to do very lightweight solution like one described below. Excerpt from the code:

* Mini-framework which implements c 'assert' macro style functions
* and allows to track and direct assertions output. Sample below illustrates
* how Assert.monitor() used to track assertions which happened
* few function calls deeper and direct assertions output to the
* code>log stream.
*

* public class SomeTests extends MultiTest {
*    // testData array(s) definitions
*    public Status testCase() {
*        return (Status)Assert.monitor(Status.passed("OKAY"), Status.failed("Test failed"), log, 
*            new Runnable(){
*                public void run(){
*                    testIteration();
*                }
*        });
*    }
*    private void testIteration(){
*        // iteration on boundary/equivalence class partitioning values
*        for( int i=0; i<testData.length; ++i){
*            testCore(testData[i]);
*        }
*    }
*    private void testCore(TestValue value){
*        //prepare test preconditions
*        Assert.isTrue(someCondition, "Some Condition failed");
*        try {
*            //do something illegal, which should lead to SomeException
*            Assert.nonReachable("SomeException expected");
*        }
*        catch(SomeException expected){
*        }
*        // Unexpected exception should be handled by JavaTest framework
*        Assert.equal(calculateExpected(), testCalculation(), "{0} and {1} supposed to be equal");
*    }
* }  
* 


* @see #monitor
* @see #isTrue

2. JavaTest and Java ME TCK Framework architectures are based on plugins that allows to support any test formats you like. There is a simple extension to JavaTest that our QA teams are using to execute standard JUnit tests. We consider adding this as suported official feature to the JT harness, as well as adding support for some of ME-specific JUnit variations to ME Framework.

Please let me know if this answers your question

Best regards
Alexey