Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of Slice Tests #189

Merged
merged 13 commits into from
Dec 22, 2024
Merged

Add example of Slice Tests #189

merged 13 commits into from
Dec 22, 2024

Conversation

rashidi
Copy link
Owner

@rashidi rashidi commented Dec 21, 2024

Summary by Sourcery

Add a module to demonstrate Slice Tests using Spring Boot Test Slice.

New Features:

  • Introduce a new module to demonstrate Slice Tests with Spring Boot.

Tests:

  • Include tests for the new module.

@rashidi rashidi added the enhancement New feature or request label Dec 21, 2024
Copy link

sourcery-ai bot commented Dec 21, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new module, test-slice-tests, which demonstrates the use of Spring Boot Slice tests. It includes a User entity, resource, and repository, along with configurations for Testcontainers and Spring Boot Test.

Class diagram for the new test-slice-tests module structure

classDiagram
    class User {
        +String id
        +String name
        +String email
    }

    class UserRepository {
        <<interface>>
        +findById(String id)
        +save(User user)
    }

    class UserResource {
        -UserRepository repository
        +getUser(String id)
        +createUser(User user)
    }

    UserResource --> UserRepository : uses
    UserRepository --> User : manages

    note for UserRepository "Spring Data Repository"
    note for UserResource "REST Controller"
Loading

File-Level Changes

Change Details Files
Added a new module named test-slice-tests which demonstrates Spring Boot Slice tests.
  • Included the new module in the root settings.gradle file.
  • Created a build.gradle file for the new module to manage dependencies and configurations.
  • Set up a basic project structure with main and test source directories.
  • Created a main application class, TestSliceTestsApplication, to bootstrap the application.
  • Created a test application class, TestTestSliceTestsApplication, to run tests with Testcontainers.
  • Added a base test class, TestSliceTestsApplicationTests, to verify the application context loads successfully.
  • Created standard .gitattributes and .gitignore files for the new module.
settings.gradle
test-slice-tests/build.gradle
test-slice-tests/settings.gradle
test-slice-tests/src/main/java/zin/rashidi/boot/test/slices/TestSliceTestsApplication.java
test-slice-tests/src/test/java/zin/rashidi/boot/test/slices/TestSliceTestsApplicationTests.java
test-slice-tests/src/test/java/zin/rashidi/boot/test/slices/TestTestSliceTestsApplication.java
test-slice-tests/src/main/resources/application.properties
test-slice-tests/.gitattributes
test-slice-tests/.gitignore
Implemented a simple User domain with related components.
  • Created a User entity with basic properties like name, username, and status.
  • Created a UserResource to expose REST endpoints for creating and reading users.
  • Created a UserRepository to interact with the database for user persistence.
test-slice-tests/src/main/java/zin/rashidi/boot/test/slices/user/User.java
test-slice-tests/src/main/java/zin/rashidi/boot/test/slices/user/UserResource.java
test-slice-tests/src/main/java/zin/rashidi/boot/test/slices/user/UserRepository.java
Configured Testcontainers for integration testing.
  • Created a TestcontainersConfiguration class to manage the PostgreSQL container.
  • Added a @ServiceConnection annotated PostgreSQLContainer bean to provide a database connection for tests.
test-slice-tests/src/test/java/zin/rashidi/boot/test/slices/TestcontainersConfiguration.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rashidi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The PR sets up the infrastructure but is missing actual slice test examples (@WebMvcTest, @DataJpaTest, etc.) which are needed to demonstrate the different types of Spring Boot slice tests. Please add these test examples to fulfill the module's purpose.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rashidi rashidi self-assigned this Dec 21, 2024
@rashidi rashidi merged commit e1ddee3 into master Dec 22, 2024
6 checks passed
@rashidi rashidi deleted the test/slice-tests branch December 22, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant