forked from dork/tarantool-java
-
Notifications
You must be signed in to change notification settings - Fork 19
Closed
Labels
code healthImprove code readability, simplify maintenance and so onImprove code readability, simplify maintenance and so on
Description
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));
}
...
}Metadata
Metadata
Assignees
Labels
code healthImprove code readability, simplify maintenance and so onImprove code readability, simplify maintenance and so on