<commit_before># JUnit 5

Junit 5 [user guide](https://junit.org/junit5/docs/current/user-guide/)

You will need the following dependencies (assuming BOM used for versions management):

```groovy
testImplementation 'io.dropwizard:dropwizard-testing'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter'
```

!!! tip
    If you already have junit4 or spock tests, you can activate [vintage engine](https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4) 
    so all tests could work  **together** with junit 5: 
    ```groovy    
    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
    ```

## Dropwizard extensions compatibility

Guicey extensions can be used with dropwizard extenssions. But this may be required only in edge cases
when multiple applications startup is required.

!!! info
    There is a difference in extensions implementation. 
    
    Dropwizard extensions work as:
    junit extension `@ExtendWith(DropwizardExtensionsSupport.class)` looks for fields 
    implementing `DropwizardExtension` (like `DropwizardAppExtension`) and start/stop them according to test lifecycle.
    
    Guicey extensions completely implemented as junit extensions (and only hook fields are manually searched). 
    Also, guciey extension rely on junit parameters injection. Both options has pros and cons.
    

## Extensions

Provided extensions:

* `@TestGuiceyApp` - for lightweight tests (without starting web part, only guice context)
* `@TestDropwizardApp` - for complete integration tests

Both extensions allow using injections directly in test fields.

Extensions are compatible with [parallel execution](#parallel-execution) (no side effects).

[Alternative declaration](#alternative-declaration) is possible.

!!! note
    Spock and junit5 extensions are almost equivalent in features and behaviour. 
    
## @TestGuiceyApp

`@TestGuiceyApp` runs all guice logic without starting jetty (so resources, servlets and filters will not be available).
`Managed` objects will still be handled correctly.

```java
@TestGuiceyApp(MyApplication.class)
public class AutoScanModeTest {

    @Inject 
    MyService service;
    
    @Test
    public void testMyService() {        
        Assertions.assertEquals("hello", service.getSmth());     
    }
```

Also, injections work as method parameters:

```java
@TestGuiceyApp(MyApplication.class)
public class AutoScanModeTest {
    
    public void testMyService(MyService service) {        
        Assertions.assertEquals("hello", service.getSmth());     
    }
```

Application started before all tests in annotated class and stopped after them.

## @TestDropwizardApp

`@TestDropwizardApp` is useful for complete integration testing (when web part is required):

```groovy
@TestDropwizardApp(MyApplication.class)
class WebModuleTest extends Specification {

    @Inject 
    MyService service

    @Test
    public void checkWebBindings(ClientSupport client) {

        Assertions.assertEquals("Sample filter and service called", 
            client.targetMain("servlet").request().buildGet().invoke().readEntity(String.class));
        
        Assertions.assertTrur(service.isCalled());
```<commit_msg>fix junit 5 example typo; mention required gradle configuration<commit_after># JUnit 5

Junit 5 [user guide](https://junit.org/junit5/docs/current/user-guide/)

You will need the following dependencies (assuming BOM used for versions management):

```groovy
testImplementation 'io.dropwizard:dropwizard-testing'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter'
```

!!! tip
    If you already have junit4 or spock tests, you can activate [vintage engine](https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4) 
    so all tests could work  **together** with junit 5: 
    ```groovy    
    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
    ```

!!! note
    In gradle you need to explicitly [activate junit 5 support](https://docs.gradle.org/current/userguide/java_testing.html#using_junit5) with
    ```groovy
    test {
        useJUnitPlatform()
        ...
    }                    
    ```

## Dropwizard extensions compatibility

Guicey extensions can be used with dropwizard extenssions. But this may be required only in edge cases
when multiple applications startup is required.

!!! info
    There is a difference in extensions implementation. 
    
    Dropwizard extensions work as:
    junit extension `@ExtendWith(DropwizardExtensionsSupport.class)` looks for fields 
    implementing `DropwizardExtension` (like `DropwizardAppExtension`) and start/stop them according to test lifecycle.
    
    Guicey extensions completely implemented as junit extensions (and only hook fields are manually searched). 
    Also, guciey extension rely on junit parameters injection. Both options has pros and cons.
    

## Extensions

Provided extensions:

* `@TestGuiceyApp` - for lightweight tests (without starting web part, only guice context)
* `@TestDropwizardApp` - for complete integration tests

Both extensions allow using injections directly in test fields.

Extensions are compatible with [parallel execution](#parallel-execution) (no side effects).

[Alternative declaration](#alternative-declaration) is possible.

!!! note
    Spock and junit5 extensions are almost equivalent in features and behaviour. 
    
## @TestGuiceyApp

`@TestGuiceyApp` runs all guice logic without starting jetty (so resources, servlets and filters will not be available).
`Managed` objects will still be handled correctly.

```java
@TestGuiceyApp(MyApplication.class)
public class AutoScanModeTest {

    @Inject 
    MyService service;
    
    @Test
    public void testMyService() {        
        Assertions.assertEquals("hello", service.getSmth());     
    }
```

Also, injections work as method parameters:

```java
@TestGuiceyApp(MyApplication.class)
public class AutoScanModeTest {
    
    public void testMyService(MyService service) {        
        Assertions.assertEquals("hello", service.getSmth());     
    }
```

Application started before all tests in annotated class and stopped after them.

## @TestDropwizardApp

`@TestDropwizardApp` is useful for complete integration testing (when web part is required):

```groovy
@TestDropwizardApp(MyApplication.class)
class WebModuleTest {

    @Inject 
    MyService service

    @Test
    public void checkWebBindings(ClientSupport client) {

        Assertions.assertEquals("Sample filter and service called", 
            client.targetMain("servlet").request().buildGet().invoke().readEntity(String.class));
        
        Assertions.assertTrur(service.isCalled());
```
{'fraction_non_alphanumeric': 0.08630643967431532, 'fraction_numerical': 0.0028127313101406364, 'mean_word_length': 4.038031319910514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420094', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1794, 'n_words': 601}