Skip to content

test: improve test locality #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nicktorwald opened this issue May 20, 2019 · 2 comments · Fixed by #192
Closed

test: improve test locality #188

nicktorwald opened this issue May 20, 2019 · 2 comments · Fixed by #192
Labels
code health Improve code readability, simplify maintenance and so on

Comments

@nicktorwald
Copy link

nicktorwald commented May 20, 2019

At least, we need to increase test locality moving arrange-act-assert pattern within one test method or at most in one test class for the reused arrangements (@ before / @ after).

An example of a test class structure:

@DisplayName("A resultSet")
class SelectOperationIT {
    
    // text fixture
    Statement statement;
    ...

    // reused for each test preparations
    @BeforeEach
    public void setUp() throws Exception {
        statement.executeUpdate("CREATE TABLE test (id INT PRIMARY KEY, val VARCHAR(50))");
    }

    // cleanup garbage after the test execution
    @AfterEach
    public void tearDown() throws Exception {
        statement.executeUpdate("DROP TABLE test");
    }

    @Test
    @DisplayName("fetched one row by id = 1")
    public void testOneRowSelect() {
        // arrange (given)
        String insertQuery = "INSERT INTO test VALUES (1, 'a');
        statement.executeUpdate(insertQuery);
        
        // act (when)
        String selectQuery = "SELECT * FROM test WHERE id = 1";	
        ResultSet resultSet = statement.executeUpdate(selectQuery);
        resultSet.next();
    
        // assert (then)
        int expectedResultId = 1;
        String expectedResultValue = "a";
        assertEquals(expectedResultId, result.getInt(1));
        assertEquals(expectedResultValue, result.getString(2));
    }

     ...
}
@nicktorwald nicktorwald added the code health Improve code readability, simplify maintenance and so on label May 20, 2019
@nicktorwald
Copy link
Author

@Totktonada any extra thoughts about it?

@Totktonada
Copy link
Member

Agreed. No, I have no extra thoughts.

nicktorwald added a commit that referenced this issue May 28, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding the deep hierarchies
should increase test readability.

Closes: #188
nicktorwald added a commit that referenced this issue May 28, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding deep hierarchies
should increase a test readability.

Closes: #188
nicktorwald added a commit that referenced this issue Jun 11, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding deep hierarchies
should increase a test readability.

Closes: #188
nicktorwald added a commit that referenced this issue Jun 12, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding deep hierarchies
should increase a test readability.

Closes: #188
nicktorwald added a commit that referenced this issue Jun 12, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding deep hierarchies
should increase a test readability.

Closes: #188
nicktorwald added a commit that referenced this issue Jun 12, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding deep hierarchies
should increase a test readability.

Closes: #188
nicktorwald added a commit to nicktorwald/tarantool-java that referenced this issue Jul 1, 2019
Many test cases are scattered over test hierarchies which is hard to
answer distinctly: what the state do we have before the test? what's the
flow between test executions? and so on. Avoiding deep hierarchies
should increase a test readability.

Closes: tarantool#188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Improve code readability, simplify maintenance and so on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants