Skip to content

Pass the JfrEvent object as an argument to the test methods #211

@FBibonne

Description

@FBibonne

The jfrEvent object only has meaning within a test method and should not be used to share state between test methods. Therefore it should not be an instance field but rather a local variable inside the test method. In order for JfrUnit to control the jfrEvent object, it should be passed as an argument to the method. Furthermore, this is a convenient way to provide a ready-to-use instance of jfrEvent to the test method. A test method should like :

    @Test
    @EnableEvent(FileWrite.EVENT_NAME)
    void doesItWriteTempFile(JfrEvents jfrEvents) {
        // given and when statements ...
        assertThat(jfrEvents).contains(JfrEventTypes.FILE_WRITE);
    }

Moreover, by doing so, tests classes and test methods could have package private visibility as recommended (https://rules.sonarsource.com/java/RSPEC-5786/)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions