Best Testcontainers-java code snippet using org.testcontainers.jdbc.mysql.MySQLDatabaseContainerDriverTest.shouldRespectBothUrlPropertiesAndParameterProperties
Source:MySQLDatabaseContainerDriverTest.java
...8import java.util.Properties;9import static org.assertj.core.api.Assertions.assertThat;10public class MySQLDatabaseContainerDriverTest {11 @Test12 public void shouldRespectBothUrlPropertiesAndParameterProperties() throws SQLException {13 ContainerDatabaseDriver driver = new ContainerDatabaseDriver();14 String url = "jdbc:tc:mysql:5.7.22://hostname/databasename?padCharsWithSpace=true";15 Properties properties = new Properties();16 properties.setProperty("maxRows", "1");17 try (Connection connection = driver.connect(url, properties)) {18 try (Statement statement = connection.createStatement()) {19 statement.execute("CREATE TABLE arbitrary_table (length_5_string CHAR(5))");20 statement.execute("INSERT INTO arbitrary_table VALUES ('abc')");21 statement.execute("INSERT INTO arbitrary_table VALUES ('123')");22 // Check that maxRows is set23 try (ResultSet resultSet = statement.executeQuery("SELECT * FROM arbitrary_table")) {24 resultSet.next();25 assertThat(resultSet.isFirst()).isTrue();26 assertThat(resultSet.isLast()).isTrue();...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!