Skip to content

Consider lazy instantiation of component under test to make tests mock friendly #19

@MarceloRuiz

Description

@MarceloRuiz

Consider deferring the instantiation of the visual component under test to right before the RController is retrieved to operate in the UI. In this way, users will be able to configure mocks in the test method right until the rcontroller() method is called (the point that indicates the user want to actually operate on the UI).

The problem with the @before annotation in the init method is that this method gets called before methods in the test class annotated with @before are called.

A simple way to avoid this problem could be by removing the @before annotation from init modify its signature to allow Exceptions to be thrown (see issue 17 [https://github.com//issues/17]) and replacing the rcontroller() method to perform the lazy instantiation:

// @Before  removed    
public void init() throws Exception {
    // content unchanged
}

public final RController rcontroller() throws Exception {
    if (controller == null) {
        init();
    }
    return controller;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions