-
Notifications
You must be signed in to change notification settings - Fork 4
JUnit 4
QuickPerfJUnitRunner adds QuickPerf features to default JUnit runner.
To use it, you have to this dependency
<dependency>
<groupId>org.quickperf</groupId>
<artifactId>quick-perf-junit4</artifactId>
<version>1.0.0-RC6</version>
<scope>test</scope>
</dependency>
With this dependency, you have access to core and JVM annotations.
Java code example with QuickPerfSpringRunner
import org.junit.runner.RunWith;
import quickperf.junit4.QuickPerfJUnitRunner;
@RunWith(QuickPerfJUnitRunner.class)
public class AccountTest {
}
In addition to the dependency mentioned in the QuickPerfJUnitRunner part, you have to add the dependency below to can use SQL annotations.
<dependency>
<groupId>org.quickperf</groupId>
<artifactId>quick-perf-sql-annotations</artifactId>
<version>1.0.0-RC6</version>
<scope>test</scope>
</dependency>
You also need to build a datasource proxy with QuickPerfSqlDataSourceBuilder and use this proxy in your test.
Look at the example below.
Java code example using QuickPerfSqlDataSourceBuilder and a SQL annotation
import org.junit.runner.RunWith;
import quickperf.junit4.QuickPerfJUnitRunner;
import net.ttddyy.dsproxy.support.ProxyDataSource;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.junit.Before;
import org.quickperf.sql.entities.Book;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Properties;
import org.quickperf.sql.config.QuickPerfSqlDataSourceBuilder;
import org.quickperf.sql.annotation.SelectNumber;
@RunWith(QuickPerfJUnitRunner.class)
public class bookTest {
private EntityManagerFactory emf;
@Before
public void before() {
PersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
PersistenceUnitInfo info = buildPersistenceUnitInfo();
emf = persistenceProvider.createContainerEntityManagerFactory(info, new HashMap<>());
}
private PersistenceUnitInfo buildPersistenceUnitInfo() {
DataSource baseDataSource = TestDataSourceBuilder.aDataSource().build();
ProxyDataSource proxyDataSource = QuickPerfSqlDataSourceBuilder.aDataSourceBuilder().buildProxy(baseDataSource);
Properties hibernateProperties = HibernateConfigBuilder.anHibernateConfig().build();
return PersistenceUnitInfoBuilder.aPersistenceUnitInfo()
.build(proxyDataSource
, hibernateProperties
, Book.class);
}
@ExpectMaxSelect(1)
@Test
public void should_retrieve_books_from_database() {
// ...
}
}
π Β Core
π Β JVM
π Β SQL
π Β Scopes
π Β Create an annotation
π Β JUnit 4
π Β JUnit 5
π Β TestNG
π Β Spring
π Β Detect and fix N+1 SELECT
π Β Maven performance
π Β Spring Boot - JUnit 4
π Β Spring Boot - JUnit 5
π Β Micronaut Data - JUnit 5
π Β Micronaut - Spring - JUnit 5
π Β Quarkus - JUnit 5
π Β FAQ
π Β QuickPerf code