Skip to content

Convert Docs for the Spock Testframework #2928

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

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions docs/test_framework_integration/spock.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,9 @@
Specifying the `@Testcontainers` annotation will instruct Spock to start and stop all testcontainers accordingly. This annotation
can be mixed with Spock's `@Shared` annotation to indicate, that containers shouldn't be restarted between tests.

```groovy
@Testcontainers
class DatabaseTest extends Specification {

@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer()
.withDatabaseName("foo")
.withUsername("foo")
.withPassword("secret")

def "database is accessible"() {

given: "a jdbc connection"
HikariConfig hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(postgreSQLContainer.jdbcUrl)
hikariConfig.setUsername("foo")
hikariConfig.setPassword("secret")
HikariDataSource ds = new HikariDataSource(hikariConfig)

when: "querying the database"
Statement statement = ds.getConnection().createStatement()
statement.execute("SELECT 1")
ResultSet resultSet = statement.getResultSet()
resultSet.next()

then: "result is returned"
int resultSetInt = resultSet.getInt(1)
resultSetInt == 1
}
}
```
<!--codeinclude-->
[PostgresContainerIT](../../modules/spock/src/test/groovy/org/testcontainers/spock/PostgresContainerIT.groovy) inside_block:PostgresContainerIT
<!--/codeinclude-->

## Adding Testcontainers Spock support to your project dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import spock.lang.Specification
import java.sql.ResultSet
import java.sql.Statement

// PostgresContainerIT {
@Testcontainers
class PostgresContainerIT extends Specification {

Expand Down Expand Up @@ -42,3 +43,4 @@ class PostgresContainerIT extends Specification {
}

}
// }