Answer this question: what are you trying to achieve with your test? Make sure the update works without errors? What every time you get a new ID? What table exists?
Depending on the answer, you should change your test. If you just want to know that the syntax of the instruction is correct, you do not need to do anything except run the statement (it throws an exception if there is an error due to which the test failed).
If you want to receive a new identifier each time, you must query the sequence twice and verify that the second value is different from the first.
If you want to check that a row with a new unique identifier is inserted, just start the insert and make sure it returns 1. If it works, you will find out that the primary key (identifier) has not been violated and that the row has been inserted. Therefore, the "add with unique identifier" mechanism should work.
[EDIT] It is not possible to test a trigger that adds an identifier to a new line because Oracle does not have the means to return the identifier that it just created. You can read the sequence, but there is no guarantee that nextval-1 will give you the same result as the trigger.
You can try select max(ID) , but it may fail if someone else inserts another row and executes it before you can run the query (using the default transaction level READ_COMMITTED ).
Therefore, I highly recommend to get rid of the trigger and use the standard two-stage algorithm ("get a new identifier" plus "insert with a new identifier"), which any other user uses. This will make your tests simpler and less fragile.
Aaron digulla
source share