0
0
JUnittesting~8 mins

Testing no exception thrown in JUnit - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Testing no exception thrown
Folder Structure
src/
└── test/
    └── java/
        └── com/
            └── example/
                ├── pages/
                │   └── LoginPage.java
                ├── tests/
                │   └── LoginTests.java
                ├── utils/
                │   └── TestUtils.java
                └── config/
                    └── TestConfig.java
Test Framework Layers
  • Driver Layer: Manages WebDriver setup and teardown for browser control.
  • Page Objects: Encapsulate UI elements and actions for each page (e.g., LoginPage).
  • Tests: Contains JUnit test classes with test methods verifying behavior.
  • Utilities: Helper methods for common tasks like waits, data generation.
  • Configuration: Holds environment settings, credentials, and browser options.
Configuration Patterns
  • Use TestConfig.java to load environment variables and test parameters.
  • Use system properties or a config file (e.g., config.properties) for browser choice and URLs.
  • Keep sensitive data like credentials outside source code, load securely at runtime.
  • Allow switching environments (dev, staging, prod) via config settings.
Test Reporting and CI/CD Integration
  • Use JUnit's built-in reports for pass/fail results.
  • Integrate with CI tools (Jenkins, GitHub Actions) to run tests on code changes.
  • Generate HTML or XML reports for easy review.
  • Fail build if any test throws unexpected exceptions.
Best Practices
  • Use assertDoesNotThrow() in JUnit 5 to verify no exceptions occur.
  • Write clear test method names describing the expected behavior.
  • Keep tests independent and repeatable without side effects.
  • Use Page Object Model to separate UI logic from tests.
  • Handle setup and cleanup in @BeforeEach and @AfterEach methods.
Self Check

Where in this folder structure would you add a new test method to verify that a user login does not throw any exceptions?

Key Result
Use JUnit's assertDoesNotThrow in well-structured tests under src/test/java with Page Objects and config management.