Spring:@TestConfiguration: Unterschied zwischen den Versionen

Aus Alexander's Wiki
K
Zeile 1: Zeile 1:
== Abweichende Properties-Datei ==
Annotation in der Testklasse um die ''application-text.yaml'' Datei zu verwenden:<syntaxhighlight lang="java" line="1">
@ActiveProfiles(profiles = "test")
</syntaxhighlight>Überprüfung während des Starts der AprinApplication:<syntaxhighlight lang="java" line="1">
INFO  [main] o.s.b.SpringApplication: The following profiles are active: test
</syntaxhighlight>
== Spezieller ApplicationContext ==
Annotation der Test-Klasse<syntaxhighlight lang="java" line="1">
Annotation der Test-Klasse<syntaxhighlight lang="java" line="1">
@Import(CommentServiceTest.EmployeeServiceImplTestContextConfiguration.class)
@Import(CommentServiceTest.EmployeeServiceImplTestContextConfiguration.class)

Version vom 22. November 2021, 11:35 Uhr

Abweichende Properties-Datei

Annotation in der Testklasse um die application-text.yaml Datei zu verwenden:

@ActiveProfiles(profiles = "test")

Überprüfung während des Starts der AprinApplication:

INFO  [main] o.s.b.SpringApplication: The following profiles are active: test

Spezieller ApplicationContext

Annotation der Test-Klasse

@Import(CommentServiceTest.EmployeeServiceImplTestContextConfiguration.class)
    @TestConfiguration
    static class EmployeeServiceImplTestContextConfiguration {

        @Bean
        public CommentMapper employeeService() {
            return new CommentMapper() {
                 // implement methods
            };
        }
        
    }