Search code examples
cunit-testinghwut

HWUT choice order


I am using choices in my HWUT test.

  • If in the command line, I don't specify the choice, then the test runs for all the choices.

  • And the test is run for each choice as per alphabetical order. But, I would the like the test to run the choices based on the order specified in the test file, as specified below.

For example:

printf("CHOICES: start, do_something, end");

I would like to it execute in the same order.

I did see some information regarding ordering of choices in this page.

This mentions about FIRST, NOT_LAST, NOT_FIRST, LAST. I couldn't figure out how to use this. Also, I'm not sure if this is the solution.


Solution

    1. A HWUT Test's choice relates to a test that is completely independent. Your setup procedure must create a deterministic environment and the results must not depend on external things and must not depend on the history of HWUT tests!

    2. If you have such a history dependency, then you must code the tests in a single choice (or, not having any choices at all).

    3. Sometimes you 'make/build' things that are useful for all tests. For example, you might generate a huge database that is used by all CHOICES. When the last test finishes, the huge database shall be remove from the file system. Then, it makes sense to consider FIRST and LAST.

    So, let us assume your case is case 3. Then, you check whether it is the first and/or last CHOICE by checking on argv[2] and argv[3] as described in the page that you reference.

    /* Begin of 'main()' */
    if( argc > 2 && strmp(argv[2], "FIRST") == 0 ) {
       /* Build some stuff to be used by all CHOICES. */
    }
    
    ... test current CHOICE ...
    
    /* End of 'main()' */
    if( argc > 3 && strmp(argv[3], "LAST") == 0 ) { 
       /* Delete some stuff that has been used by all CHOICES. */
    }