Menu

Testing of the Triggers

NLTC
2005-08-15
2013-04-25
  • NLTC

    NLTC - 2005-08-15

    Hi Sujit

    Is there any to test the triggers using the SQLUnit ?

    Thanks
    Meghanath

     
    • David Fishburn

      David Fishburn - 2005-09-09

      Database triggers are only executed by the database engine when DML statements (insert, update, delete) are executed against the table.

      CREATE TRIGGER tr_manager
      BEFORE UPDATE OF dept_head_id
      ON department
      REFERENCING OLD AS old_dept NEW AS new_dept
      FOR EACH ROW
      BEGIN
         UPDATE employee
         SET employee.manager_id=new_dept.dept_head_id
         WHERE employee.dept_id=old_dept.dept_id
      END

      For example, this trigger code will only be executed if I issue an update statement against the department table that changes the dept_head_id column:
      "UPDATE OF dept_head_id ON department"

      HTH,
      Dave

       
    • Sujit Pal

      Sujit Pal - 2005-12-17

      Hi Meghanath,

      Dave has already answered your question, but I just thought I'll make it more explicit.

      You can test the effects of a trigger by running the SQL that is designed to trigger it and checking for the side effects, so this would be two (or more) tests in SQLUnit. SQLUnit fires the tests in the order you specify them so you are ok there.

      So yes, its possible to use SQLUnit to test your triggers, although not in a single test. Your first test will invoke the trigger indirectly by invoking the SQL that is supposed to trigger the trigger, and your second (and subsequent) test(s) will look at the other tables the trigger was supposed to touch and verify that it did its thing correctly.

      -sujit

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.