{"id":36706616,"url":"https://github.com/helospark/spring-context-init-fail-test","last_synced_at":"2026-01-12T11:43:19.566Z","repository":{"id":74250483,"uuid":"108760865","full_name":"helospark/spring-context-init-fail-test","owner":"helospark","description":"Test that the application context failed to init due the the expected reason using JUnit and Spring, for example due to BeanCreationException.","archived":false,"fork":false,"pushed_at":"2025-08-30T05:48:06.000Z","size":12,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-30T07:20:06.872Z","etag":null,"topics":["example","failure","integration-testing","spring","spring-boot"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/helospark.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-10-29T18:41:05.000Z","updated_at":"2025-08-30T05:48:10.000Z","dependencies_parsed_at":"2023-03-04T10:15:38.107Z","dependency_job_id":null,"html_url":"https://github.com/helospark/spring-context-init-fail-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/helospark/spring-context-init-fail-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helospark%2Fspring-context-init-fail-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helospark%2Fspring-context-init-fail-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helospark%2Fspring-context-init-fail-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helospark%2Fspring-context-init-fail-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helospark","download_url":"https://codeload.github.com/helospark/spring-context-init-fail-test/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helospark%2Fspring-context-init-fail-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T10:58:46.209Z","status":"ssl_error","status_checked_at":"2026-01-12T10:58:42.742Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","failure","integration-testing","spring","spring-boot"],"created_at":"2026-01-12T11:43:18.809Z","updated_at":"2026-01-12T11:43:19.554Z","avatar_url":"https://github.com/helospark.png","language":"Java","readme":"= Testing expected exception on Spring startup\n\nTest that the application context failed to init due the the expected reason using JUnit and Spring, for example due to BeanCreationException.\n\n== Problem\n\nWhen writing full Spring (or Spring Boot) integration tests, you may want to test that the application didn't start.\n\nUnfortunately JUnit fails as soon as the application context throws an exception not even running the test, so it cannot be tested.\n\nTrivial solution is to move the application initializing inside a `@Test` method by manually calling the `main()` or starting via creating the Spring context manually.\nThese solutions are far from ideal, for one, the test annotations are not processed (ex. @SpringBootTest, @ActiveProfile, etc.), also you are rewriting the logic already in Spring.\n\nI have attempted to create some solutions to address these problems here.\nAll of the extends the original Spring Junit runner to add more functionality.\n\n== Solutions\n\n=== JUnit 4 (Vintage)\n\n - `ContextFailsUsingAnnotationTest`: Using just an annotation to see what exception happened\n - `ContextFailsUsingInspectorTest`: Same as the previous, but using an inspector\n - `ContextFailsUsingExpectedExceptionTest`: ClassRule ExpectedException to expect for exceptions in @BeforeClass\n\n=== JUnit 5 (Jupiter)\n\n- `ContextFailsUsingValidatorTest`: Using AssertJ to validate anything about that exception\n\n== Limitations\n\nYou need at least an empty `@Test` method, otherwise Junit and Spring will not try to build the context.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelospark%2Fspring-context-init-fail-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelospark%2Fspring-context-init-fail-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelospark%2Fspring-context-init-fail-test/lists"}