Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Leverage test instead of using main app #51

Open
GoncaloPT opened this issue Nov 8, 2023 · 5 comments
Open

Leverage test instead of using main app #51

GoncaloPT opened this issue Nov 8, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@GoncaloPT
Copy link

GoncaloPT commented Nov 8, 2023

Hi,
Is your feature request related to a problem? Please describe.
We would like to avoid mixing up test related code/profiles with our src. This would also help us in leveraging the already existing setup for @SpringBootTests ( spin up kafka, mockserver, postgres, etc ), instead of duplicating everything for the ijhttp integration tests.

Describe the solution you'd like
Would like a way of connecting the integration-test of ijhttp with a springboottest class.

PS: Btw, I've added a comment on a LinkedIn page, sorry for the "spam" :)

@vitalijr2 vitalijr2 self-assigned this Nov 8, 2023
@vitalijr2 vitalijr2 added the enhancement New feature or request label Nov 8, 2023
@vitalijr2
Copy link
Contributor

How I see the implementation: there is a special annotation (something like ParametrizedTest from jUnit5) that can run tests from one *.http files or bunch tests from *.http files in a directory, e.g. test/resources/http-client-test.

Then we just add to a test class (annotated with @WebMvcTest) an empty test method (annotated with @HttpClientTest) and it runs all test from *.http files that we set as parameter of our annotation.

@GoncaloPT
Copy link
Author

Seems a very good implementation idea!
Let me know if you want some external contribution; we are very interested in making this grow :)

Workaround

For now, we managed to configure our build in a way that we can leverage the testing classpath by using ( leaving this just as a reference to others, since you're implementation if a far better idea ):

In the pom.xml:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>start-integration-spring</id>
            <phase>pre-integration-test</phase>
            <configuration>
                <skip>${skipITs}</skip>
                <useTestClasspath>true</useTestClasspath>
                <mainClass>*****.IntegrationTestsEntryPoint</mainClass>
                <directories>
                    <directory>${project.build.testOutputDirectory}</directory>
                </directories>
            </configuration>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-integration-spring</id>
            <phase>post-integration-test</phase>
            <configuration>
            </configuration>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Then in your main class ( in this case kotlin but java would use the same ):

@SpringBootApplication
@Import(
    WithPostgres::class,
    WithMockServer::class,
    WithPostgres::class,
    WithRedis::class
)
open class IntegrationTestsEntryPoint {

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            SpringApplication.run(Application::class.java, *args)
        }
    }

}

The With** imports are just TestConfiguration classes with expose the TestContainer beans.

@vitalijr2
Copy link
Contributor

vitalijr2 commented Dec 3, 2023

Just note about my next steps.

I have investigated how to implement jUnit extension: unfortunately we cannot replace a test itself, we can run our code before or after test.

I have decided to go another way like other solutions already use, see Spring Boot Testing: MockMvc vs. WebTestClient vs. TestRestTemplate: to implement a builder-style component to customize command line and execute it.

@vitalijr2 vitalijr2 reopened this Dec 3, 2023
@vitalijr2 vitalijr2 linked a pull request Dec 3, 2023 that will close this issue
vitalijr2 added a commit that referenced this issue Dec 3, 2023
vitalijr2 added a commit that referenced this issue Dec 4, 2023
* Rename cli-builder to command-line; add a Spring Boot integration test as #51 proposed (see GitHub).

* Fix GitLab CI configuration

* Fix style issues and import

* Add the spring-boot-test module with autoconfiguration

* Fix GitLab CI configuration

* Add unit-tests, remove unused imports

* Clean GitLab CI configuration

* Spring Boot Test Autoconfiguration

* Descrease complexity

* Increase code coverage

* Increase code coverage

* Increase code coverage

* Fix style issue

* Increase code coverage

* Increase code coverage

* Fix style issues
@vitalijr2
Copy link
Contributor

Now implementation is in the develop branch

vitalijr2 added a commit that referenced this issue Dec 20, 2023
…est autoconfiguration. (#60)

* Bump org.jetbrains:annotations from 24.0.1 to 24.1.0 (#58)

Bumps [org.jetbrains:annotations](https://github.com/JetBrains/java-annotations) from 24.0.1 to 24.1.0.
- [Release notes](https://github.com/JetBrains/java-annotations/releases)
- [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md)
- [Commits](JetBrains/java-annotations@24.0.1...24.1.0)

---
updated-dependencies:
- dependency-name: org.jetbrains:annotations
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump org.apache.maven.plugins:maven-project-info-reports-plugin (#59)

Bumps [org.apache.maven.plugins:maven-project-info-reports-plugin](https://github.com/apache/maven-project-info-reports-plugin) from 3.4.5 to 3.5.0.
- [Commits](apache/maven-project-info-reports-plugin@maven-project-info-reports-plugin-3.4.5...maven-project-info-reports-plugin-3.5.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-project-info-reports-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add the proxy feature

* The report path is customazible

* CLI builder

* Update ChangeLog

* Bump actions/setup-java from 3 to 4 (#62)

Bumps [actions/setup-java](https://github.com/actions/setup-java) from 3 to 4.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update Maven plugin's groupId

* Bump mockito.version from 5.7.0 to 5.8.0 (#65)

Bumps `mockito.version` from 5.7.0 to 5.8.0.

Updates `org.mockito:mockito-core` from 5.7.0 to 5.8.0
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v5.7.0...v5.8.0)

Updates `org.mockito:mockito-junit-jupiter` from 5.7.0 to 5.8.0
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v5.7.0...v5.8.0)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
  dependency-type: direct:development
  update-type: version-update:semver-minor
- dependency-name: org.mockito:mockito-junit-jupiter
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix GitLab CI configuration

* Fix GitLab CI configuration

* Fix GitLab CI configuration

* Fix stderr integration test

* Fix style issue

* Fix GitLab CI configuration

* Spring Boot Test extension with autoconfiguration

* Rename cli-builder to command-line; add a Spring Boot integration test as #51 proposed (see GitHub).

* Fix GitLab CI configuration

* Fix style issues and import

* Add the spring-boot-test module with autoconfiguration

* Fix GitLab CI configuration

* Add unit-tests, remove unused imports

* Clean GitLab CI configuration

* Spring Boot Test Autoconfiguration

* Descrease complexity

* Increase code coverage

* Increase code coverage

* Increase code coverage

* Fix style issue

* Increase code coverage

* Increase code coverage

* Fix style issues

* Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.2 to 3.6.3 (#68)

Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.2 to 3.6.3.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](apache/maven-javadoc-plugin@maven-javadoc-plugin-3.6.2...maven-javadoc-plugin-3.6.3)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update documentation

* spring-boot-test: parameters documentation

* Add javadoc and readme to the command-line module

* Update reamde and javadoc

* Add readme and javadoc to Spring Boot Test autoconfiguration

* Update site

* Bump org.apache.maven.plugins:maven-failsafe-plugin from 3.2.2 to 3.2.3 (#71)

Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](apache/maven-surefire@surefire-3.2.2...surefire-3.2.3)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-failsafe-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.2 to 3.2.3 (#70)

Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](apache/maven-surefire@surefire-3.2.2...surefire-3.2.3)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github/codeql-action from 2 to 3 (#72)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Next version

* Update TOC in readme

* Fix TOC

* Update javadoc and release profile

* Bump org.apache.maven.plugins:maven-compiler-plugin (#74)

Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.11.0 to 3.12.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](apache/maven-compiler-plugin@maven-compiler-plugin-3.11.0...maven-compiler-plugin-3.12.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-compiler-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@vitalijr2
Copy link
Contributor

Implemented in v1.1.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants