-
Notifications
You must be signed in to change notification settings - Fork 0
Integrated Testing
ganmath edited this page Apr 21, 2024
·
1 revision
- Spring Boot project for Business Logic (Project 1)
- Spring Boot project for Selenium and Cucumber (Project 2)
- Angular project for UI (Project 3)
This project will focus on handling the business operations and data interactions.
- Initialize the project using Spring Initializr or your preferred method, adding dependencies such as Spring Web, Spring Data JPA for database operations, and any other necessary business logic dependencies.
-
src/main/java/for your business logic -
src/main/resources/for configuration files -
src/test/java/for your testing code
-
Add JUnit and Mockito Dependencies:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
-
Write Unit Tests:
- Create test cases in
src/test/java/to validate each component of your business logic using JUnit. - Example for a service class:
@ExtendWith(SpringExtension.class) public class UserServiceTest { @Mock private UserRepository userRepository; @InjectMocks private UserService userService; @Test public void testFindUserById() { User user = new User(1L, "John Doe"); Mockito.when(userRepository.findById(1L)).thenReturn(Optional.of(user)); User found = userService.findUserById(1L); assertEquals("John Doe", found.getName()); } }
- Create test cases in
-
Mock Testing:
- Use Mockito to mock dependencies in the tests to ensure each unit test is isolated from others.
This project will handle all automated BDD tests using Selenium WebDriver and Cucumber.
- Initialize a separate Spring Boot project.
-
Add Cucumber and Selenium Dependencies:
<dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-spring</artifactId> <version>YourCucumberVersion</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>YourSeleniumVersion</version> <scope>test</scope> </dependency>
-
Feature Files:
- Place your feature files under
src/test/resources/features.
- Place your feature files under
-
Step Definitions and Test Runner:
- Organize step definitions under
src/test/java/your/package/stepdefs. - Use the Spring context for dependency injection and setup web driver management.
- Organize step definitions under
-
Configure Cucumber-Spring Integration:
@RunWith(Cucumber.class) @CucumberOptions( features = "src/test/resources/features", glue = "your.package.stepdefs" ) public class TestRunner {}
This project will be a standard Angular application handling the user interface.
-
Generate the project using Angular CLI:
ng new your-project-name - Develop your components, services, and modules as required for the UI.
Ensure that each project is capable of running independently and has its own testing setup. For integration:
- Backend (Project 1) should expose an API consumed by the Angular frontend (Project 3).
- Test Automation (Project 2) should be configured to interact with either a staging environment or directly with the development build, ideally in a CI/CD pipeline to ensure tests are run against the most recent version of the backend and frontend.
This structure promotes separation of concerns, making it easier to manage and scale your projects independently while maintaining a robust testing environment across the development lifecycle.