Integration with Test NG
Sniffy comes with a Test NG listener
for quick integration with test framework.
Just add @Listeners(SniffyTestNgListener.class)
to your TestNG test class and place appropriate expectations on your test methods like shown below.
package io.sniffy.test.testng.usage;
import io.sniffy.sql.SqlExpectation;
import io.sniffy.test.Count;
import io.sniffy.test.testng.SniffyTestNgListener;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@Listeners(SniffyTestNgListener.class) (1)
public class UsageTestNg {
@Test
@SqlExpectation(count = @Count(1)) (2)
public void testJUnitIntegration() throws SQLException {
final Connection connection = DriverManager.getConnection("sniffy:jdbc:h2:mem:", "sa", "sa"); (3)
connection.createStatement().execute("SELECT 1 FROM DUAL"); (4)
}
}
-
- Integrate
Sniffy
to your test using@Listeners(SniffyTestNgListener.class)
. -
- Now just add
@SqlExpectation
annotation to define number of queries allowed for given method. -
- Just add
sniffy:
in front of your JDBC connection URL in order to enable sniffer. -
- Do not make any changes in your code - just add the
@Listeners(SniffyTestNgListener.class)
and put annotations on your test method.