Thanks Jeff
Will give it a go.
Riaan
On Thu, 15 Jun 2006 12:53:18 +0200
JeffM <[EMAIL PROTECTED]> wrote:
>
>TestSuite does indeed take arguments of type typeTestCase
>, hence the
>error.It's obviously included for backwards
>compatibility.Anyway
>before I get dragged by the tangent drift , all you need
>to do is
>create a class annotated with @RunWith and @SuiteClasses
>as shown
>below :
>
>@RunWith(Suite.class)
>@SuiteClasses( { ArithmeticTest.class,
>AnotherArithmeticTest.class })
>public class AllTests {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> junit.textui.TestRunner.run(suite());
> }
>
> public static Test suite() {
> return new JUnit4TestAdapter(AllTests.class);
> }
>
>}
>
>where ArithmeticTest.java AnotherArithmeticTest.java are
>the indivual
>test classes you wish to include in your testsuite.They
>both don't
>have to extend TestCase (your wish granted).I tested this
>from within
>Eclipse.Don't think you'll have any problems
>
>
>
>
>On 6/14/06, Riaan Koegelenberg
><[EMAIL PROTECTED]> wrote:
>>
>> Hi Jeff
>>
>> Below is part of one of my test classes:
>>
>>
>> import za.co.q3.prophecy_PM.dao.*;
>> import java.sql.*;
>>
>> import ......
>>
>> public class testAuditDAO {
>>
>> //Class for getting connection
>> private SysConnection dbconn;
>> private Connection conn;
>> private ResultSet resultSet;
>> private SysUtil sysUtil = new SysUtil();
>> private PreparedStatement preparedStatement;
>>
>> private int actualAuditId = sysUtil.getGuid();
>> private int expectedAuditId = 0;
>>
>> public static junit.framework.Test suite() {
>> //allow this test to be run with the old
>test runners
>> return new
>JUnit4TestAdapter(testAuditDAO.class);
>> }
>>
>> @Before public void runBeforeEachTest() throws
>> SQLException{
>> //Executes before each test
>> conn = dbconn.getConn();
>> //Make sure the connection is not null
>> assertNotNull(conn);
>> }
>>
>> @After public void runAfterEachTest() throws
>SQLException{
>> //Executes after each test
>> dbconn.freeConnection(conn);
>> conn = null;
>> //make sure connection is closed
>> assertNull(conn);
>> }
>>
>> /*
>> *Test Adding of Records
>> */
>> @Test public void AddRecord() throws
>SQLException{
>> try{
>> preparedStatement =
>>
>conn.prepareStatement(dbconn.getSqlProperty("AuditDAO.addData"));
>> //set parameters
>>
>> preparedStatement.setString(1,
>> String.valueOf(actualAuditId));
>>
>>
> preparedStatement.executeUpdate();
>> }
>> catch (Exception e){
>> fail("Error when adding record:
>" + e.getMessage());
>> }
>> finally {
>> preparedStatement.close();
>> }
>> }
>>
>> @Test public void GetAddedRecord() throws
>SQLException{
>> try{
>> preparedStatement =
>conn.prepareStatement("Select * from
>> Audit where AuditId = " + actualAuditId);
>>
>> resultSet =
>preparedStatement.executeQuery();
>>
>> if (resultSet.next()) {
>> //populate expected variables
>with values retrieved from
>> DB
>> expectedAuditId =
>> Integer.parseInt(resultSet.getString("auditId"));
>> }
>> else{
>> //No relevant record in
>the DB
>> fail("GetAddedRecord -
>No records where returned from
>> the database.");
>> }
>> resultSet.close();
>> }
>> catch(Exception e){
>> fail("GetAddedRecord - Error
>when retrieving record: " +
>> e.getMessage());
>> }
>> finally{
>> preparedStatement.close();
>> }
>> //Do comparison between actual and
>expected record
>> DoAddCompare();
>> }
>>
>> private void DoAddCompare(){
>>
>> try{
>> assertEquals("The Audit_Id is
>not correct.",
>> expectedAuditId, actualAuditId);
>> }
>> catch(Exception e){
>> fail("Can't compare AuditId: " +
>e.getClass() + " - " +
>> e.getMessage());
>> }
>> }
>>
>>
>>
>> }
>>
>>
>> And this is the suite that I am trying to create. It is
>> complaining because my class (testAuditDAO) does not
>extend
>> TestCase:
>>
>>
>> import junit.framework.Test;
>> import junit.framework.TestSuite;
>> import za.co.q3.prophecy_PM.junit.dao.*;
>>
>> public class TestDAOSuite {
>>
>> public static Test suite() {
>>
>> TestSuite suite = new TestSuite();
>>
>> // Add all DAO test classes
>> suite.addTestSuite(testAuditDAO.class);
>>
>> return suite;
>> }
>>
>> // Runs the test suite using the textual runner.
>> public static void main(String[] args) {
>> junit.textui.TestRunner.run(suite());
>> }
>> }
>>
>>
>___________________________________________________________________
>> For super low premiums, click here
>http://www.webmail.co.za/dd.pwm
>>
>> http://www.webmail.co.za the South African FREE email
>service
>>
>> >
>>
>
>
>--
>
>
>Jeff Mutonho
>
>GoogleTalk : ejbengine
>Skype : ejbengine
>Registered Linux user number 366042
>
>>
___________________________________________________________________
For super low premiums, click here http://www.webmail.co.za/dd.pwm
http://www.webmail.co.za the South African FREE email service
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---