“Multiverse” – Unit Testing of “Parallel Realities”

“Multiverse” is a simple solution for the so-called combinatorial problem of testing. Using “multiverse” technique, at certain points of tests one can specify choices. During a repeated execution of tests, each specified part of the respective test case is executed multiple times so that all combination of choices (i.e., all paths, from the intial point to each leaves) are tested. Multiverse can also be used to execute a random selection of choices within a single run, simulating the behaviour of users, and concurrent random executions can be used for stress tests. (The name „Multiverse” comes from the hypothesis of parallel universes.)

There's a short documentation presenting the “Multiverse” technique.

Firefly has a built in 'Multiverse' handler. There's a video of an example 'Multiverse' run.

Java implementation of “Multiverse” is packaged in ONCE Utilities, thus it can be used as a maven artifact.


The simplest way to specify possible alternate branches is as follows (first three choices are 0,1,2, the second choices are 0,1):

    @Test public void test()  {
        // initial steps…
        do {
            // repeated initial steps…
            switch ( Multiverse.of(3) ) {
                case 0: // steps of testing the A... branch
                        switch ( Multiverse.of(2) ) {
                            case 0: 
                                // steps of testing the A0... branch 
                                break; 
                            case 1: 
                                // steps of testing the A1... branch 
                                break; 
                        }
                    break; 
                case 1: // steps of testing the B... branch 
                    break; 
                case 2: 
                    // steps of testing the C... branch 
                    break; 
            }
            // repeated final steps…
        } while( Multiverse.next() );
        // final steps…
    }
ww/multiverse.txt · Last modified: 2017/01/10 08:22 (external edit)
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0