You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I've recently started working with CAP Java and have some questions about the Testing documentation. I hope to get some clarification here or possibly see these addressed in a future update to the documentation.
The current documentation categorizes testing into three types:
Event Handler Layer Testing
Service Layer Testing
Integration Testing
Use Case
I have the following files:
UserImportService.cds: A CDS service file providing a custom action import for bulk user creation.
UserImportHandler.cds: A service handler file implementing the custom action logic.
I need to test the following scenarios:
Case 1: Validate HTTP response codes:
Correct JSON request → HTTP 2xx
Invalid JSON/missing auth → Corresponding 4xx
Case 2: Handle invalid request bodies:
Missing fields or invalid types → Expected exception and no database entries
Case 3: Verify field mapping:
Ensure input fields are correctly mapped to output values using the service handler’s mapper classes.
Case 4: Ensure transactional integrity:
If one user creation fails, no users should be created in the database.
Current Testing Approach
To cover the above scenarios, I currently employ the following three testing types:
Unit Tests (...MapperTest.java)
Test mapping logic for Case 3 using mocks.
Service Layer Tests (UserImportServiceTest.java with @SpringBootTest)
Validate business logic for Case 2 and Case 4 with Java entity objects as request body
Integration Tests (UserImportServiceITest.java with @SpringBootTest)
Test end-to-end HTTP calls for Case 1 with JSON request body
Challenges and Questions
Overlapping Tests:
Service Layer Tests and Integration Tests have overlaps (although Service Layer Tests include many more edge cases). Is there a best practice for distinguishing these types of tests?
Naming Confusion:
File names like UserImportServiceTest.java and UserImportServiceITest.java can confuse future developers about where to add new tests. Could you suggest clearer naming conventions?
Terminology in Documentation:
Why does the documentation refer to Service Layer test files as ...ServiceTest.java when the default handler files are named ...Handler.java? This could be confusing, especially in projects where a ...Service.java file might exist for additional business logic.
Performance vs. Mocking:
Tests with @SpringBootTest are slower than unit tests with mocks. However, heavy mocking can make the test code complex. What is the recommended balance between these approaches?
Example Projects:
Is there a large CAP example project demonstrating these three testing types in a structured way?
Thank you for your time! I look forward to your insights and suggestions.
The text was updated successfully, but these errors were encountered:
Hi, I've recently started working with CAP Java and have some questions about the Testing documentation. I hope to get some clarification here or possibly see these addressed in a future update to the documentation.
The current documentation categorizes testing into three types:
Use Case
I have the following files:
UserImportService.cds
: A CDS service file providing a custom actionimport
for bulk user creation.UserImportHandler.cds
: A service handler file implementing the custom action logic.I need to test the following scenarios:
Current Testing Approach
To cover the above scenarios, I currently employ the following three testing types:
...MapperTest.java
)UserImportServiceTest.java
with@SpringBootTest
)UserImportServiceITest.java
with@SpringBootTest
)Challenges and Questions
Overlapping Tests:
Naming Confusion:
UserImportServiceTest.java
andUserImportServiceITest.java
can confuse future developers about where to add new tests. Could you suggest clearer naming conventions?Terminology in Documentation:
...ServiceTest.java
when the default handler files are named...Handler.java
? This could be confusing, especially in projects where a...Service.java
file might exist for additional business logic.Performance vs. Mocking:
@SpringBootTest
are slower than unit tests with mocks. However, heavy mocking can make the test code complex. What is the recommended balance between these approaches?Example Projects:
Thank you for your time! I look forward to your insights and suggestions.
The text was updated successfully, but these errors were encountered: