I created a JUnit4 TestCase for my Shard class, but when I try to extend GroovyTestCase it does not run my @BeforeClass and @AfterClass methods.
Here is my code
import groovy.sql.*
import org.junit.*
class ShardUnitTests {
static def shard
static def sql
static def mysqlserver = "REDACTED"
@BeforeClass
static void beforeClassSetUp(){
def db = [url:'jdbc:mysql://${mysqlserver}:3306/test', user:'root', password:'password', driver:'com.mysql.jdbc.Driver']
sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
shard = new Shard(sql: sql)
}
@AfterClass
static void afterClassTearDown(){
sql.execute("DROP TABLE test")
sql.close()
}
@Test
//Test that createObjectTable creates a table with 2 columns
void testCreateObjectTable(){
shard.createObjectTable("test")
sql.rows("SELECT * FROM test"){meta ->
assert meta.getColumnName(1) == "id"
assert meta.getColumnName(2) == "data"
}
}
}
When I change the class definition to
class ShardUnitTests extends GroovyTestCase{
the beforeClassSetUp() and afterClassTearDown() methods are not called. Is there some other syntax I should be using for these methods, or is it just not compatible with GroovyTestCase?