1 Aralık 2022 Perşembe

JUnit4 @ClassRule Anotasyonu

Giriş
Açıklaması şöyle. Yani JUnit 4'teki ClassRule gibidir.
Both JUnit4 and JUnit5 offer a solution to manage external resources as part of the test class definition. JUnit4 exposes this functionality via ClassRule, while JUnit5 provides a more powerful approach called Extension.

ClassRule exposes two functions: before and after, the former is used to set up the rule, and the latter is used to clean it up. If a test class contains a ClassRule definition, JUnit will invoke the before function before running any tests; after every test run, independently from their results, JUnit will invoke the function after. Extensions in JUnit5 follow the same pattern with an enriched semantic.
Birden fazla ClassRule varsa açıklaması şöyle
If there are multiple annotated ClassRules on a class, they will be applied in an order that depends on your JVM's implementation of the reflection API, which is undefined, in general. However, Rules defined by fields will always be applied before Rules defined by methods.
Örnek
Şöyle yaparız
@ClassRule
public static final SharedKafkaTestResource kafka = new SharedKafkaTestResource().withBrokers(1); private static final SharedSchemaRegistryTestResource schemaRegistry = new SharedSchemaRegistryTestResource() .withBootstrapServers(kafka::getKafkaConnectString); @ClassRule public static TestRule schemaRegistry() { return schemaRegistry; }




Hiç yorum yok:

Yorum Gönder