This all has to do with JUnit, nothing maven specific. If you want to write a TestSuite that runs all of the tests you specify, you can use a solution like http://junit.sourceforge.net/doc/faq/faq.htm#organize_3. I'm almost positive that maven will not pick up a test class unless the name of the class ends in "Test". However, you can specify that maven runs only the TestSuite like "maven -Dtestcase=AllTests test:single".
Here's an example of having a TestSetup run only once for all unittests using a different method. // This is not a test class public class DbSetup extends TestSetup { private static Connection _conn; public DbSetup(Test suite) { super(suite); } public void setUp() throws Exception { if (_conn == null) { // will only start database once for all tests Class.forName("org.hsqldb.jdbcDriver"); _conn = DriverManager.getConnection("jdbc:hsqldb:.", "sa", ""); // LOAD SCHEMA HERE } } public void tearDown() { // do nothing, db will shut down when JVM exists or _conn is closed } public Connection getConnection() { return _conn; } } // This is a test class public class JDBCTest extends TestCase { private static DbSetup _db; public static Test suite() { TestSuite suite = new TestSuite(JDBCTest.class); _db = new DbSetup(suite); return _db; } public void testSomething() { Connection conn = _db.getConnection(); } } If you go with that solution -jake On Wednesday 05 January 2005 04:01 pm, Charles N. Harvey III wrote: > This is exactly what I was looking for. I'm still playing with it > to get it to work out correctly, but it is in the right direction, thanks. > > If I write a TestSuite (AllTests.java), will it run first? That's one > thing that I was never sure of. Do the tests all run individually or > does the Suite get executed and then it runs the tests? > > Just curious, I just didn't know how that part of the test framework > of maven worked. > > Thanks again. > > > Charlie > > > > Jake Ewerdt said the following on 1/5/2005 3:09 PM: > > >I set up the HSQL database in the JUnit TestSetup. This drops and > >re-creates the database for each test class that need the database, but the > >overhead is quite low, only a few test classes need the database running, > >and it ensures left over database artifacts will not have any side-effects > >on future tests. Only starting the database and creating the tables once > >for all tests can be easily accomplished by keeping around the static > >connection and have all test classes get that connection instead of doing > >the setup themselves. > > > >The code looks something like this: > > > >public class JDBCTest extends TestCase { > > private static Connection conn; > > > > public static Test suite() { > > TestSuite suite = new TestSuite(JDBCTest.class); > > > > TestSetup wrapper = new TestSetup(suite) { > > protected void setUp() > > throws Exception { > > Class.forName("org.hsqldb.jdbcDriver"); > > conn = DriverManager.getConnection("jdbc:hsqldb:.", "sa", ""); > > // LOAD SCHEMA HERE > > } > > protected void tearDown() > > throws Exception { > > conn.close(); > > } > > }; > > return wrapper; > > } > > > > public void testSomething() { > > } > >} > > > >I use a file-based db by replacing "jdbc:hsqldb:." with something like > >"jdbc:hsqldb:tmpdb" only if I need to view the actual tables or data in the > >database. > > > >-jake > > > > > >On Wednesday 05 January 2005 11:35 am, Charles N. Harvey III wrote: > > > > > >>Hello. > >>I have been doing lots of reading about how great it is to use an in-process > >>DB like Hypersonic for testing. Thing is, there are not many examples of > >>how to do this. What I want to do is start an in-memory DB (not a file DB > >>because the test is small) when I run my tests, and then run tests. > >> > >>So the first thing that has to happen when I run "maven test" is that the > >>DB has to be created. Then I have to execute CREATE statements for the > >>necessary tables. Then I can proceed with my tests. > >> > >>Has anyone done this? Should I use a file-based DB instead of in memory? > >>How do I get the maven test suite to "do this one thing first, and only > >>once"? > >> > >>Any help is greatly appreciated. > >> > >> > >>Charlie > >> > >> > >>--------------------------------------------------------------------- > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > >> > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]