-
Notifications
You must be signed in to change notification settings - Fork 4
Example illustrating how annotation scopes work
Jean Bisutti edited this page Jul 16, 2020
·
7 revisions
To configure global annotations, i.e., annotations applying on each test, create a class implementing SpecifiableGlobalAnnotations
and locate it in org.quickperf
package:
package org.quickperf;
import org.quickperf.config.SpecifiableGlobalAnnotations;
import org.quickperf.sql.annotation.SqlAnnotationBuilder;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
/*The configuration class has to be in org.quickperf package*/
public class QuickPerfConfiguration implements SpecifiableGlobalAnnotations {
public Collection<Annotation> specifyAnnotationsAppliedOnEachTest() {
// CoreAnnotationBuilder, SqlAnnotationBuilder and JvmAnnotationBuilder help to build and configure global annotations
Annotation expectedSelectNumber = SqlAnnotationBuilder.expectSelectNumber(3);
return Collections.singletonList(expectedSelectNumber);
}
}
import org.junit.Test;
public class AClassWithGlobalScopeAnnotationAppliedTest {
//@ExpectSelectNumber(3) annotation is applied
@Test
public void a_test_method() {
//...
}
}
package org.mycompany;
import org.junit.Test;
import org.quickperf.sql.annotation.MaxSqlSelect;
@ExpectSelectNumber(2) // CLASS SCOPE
// This annotation overrides the annotation
// defined in QuickPerfConfiguration class (GLOBAL SCOPE)
public class AClassWithAnnotationsTest {
// @ExpectSelectNumber(2) annotation placed on class is applied
@Test
public void a_test_method() {
//...
}
@ExpectSelectNumber(1) // METHOD SCOPE
// This annotation overrides the annotation placed
// on class
@Test
public void a_test_method_with_quick_perf_annotation() {
//...
}
}
π Β 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