{"url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230","forks_url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/forks","commits_url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/commits","id":"3dcaaf3cf6cbbf18f88728ec78dc7230","node_id":"MDQ6R2lzdDNkY2FhZjNjZjZjYmJmMThmODg3MjhlYzc4ZGM3MjMw","git_pull_url":"https://gist.github.com/3dcaaf3cf6cbbf18f88728ec78dc7230.git","git_push_url":"https://gist.github.com/3dcaaf3cf6cbbf18f88728ec78dc7230.git","html_url":"https://gist.github.com/michaellihs/3dcaaf3cf6cbbf18f88728ec78dc7230","files":{"spring-boot-testing.md":{"filename":"spring-boot-testing.md","type":"text/markdown","language":"Markdown","raw_url":"https://gist.githubusercontent.com/michaellihs/3dcaaf3cf6cbbf18f88728ec78dc7230/raw/9e29e7ed0c97e99241371322a9b7cfccdcfcaa71/spring-boot-testing.md","size":1337,"truncated":false,"content":"Spring Boot Testing\n===================\n\nUsing Configuration in Tests\n----------------------------\n\nThe following snippets loads the application context with the configuration given in `TestConfiguration.class`\n\n``` java\n@RunWith(SpringRunner.class)\n@SpringBootTest(classes = TestConfiguration.class)\npublic class TestWithContext {\n\n}\n```\n\nOverride Configuration in Tests\n-------------------------------\n\nWith the following snippet you can include the configuration from `BasicConfiguration` and then override it in `TestConfiguration`\n\n```java\n@RunWith(SpringRunner.class)\n@SpringBootTest(classes = TestWithContext.TestConfiguration.class)\npublic class TestWithContext {\n\n    @Configuration\n    @Import(BasicConfiguration.class)\n    public static class TestConfiguration {\n\n        @Bean\n        ...\n\n    }\n    \n}\n```\n\nEnable Component Scan in Tests\n------------------------------\n\nIf you want to use classes annotated with `@Component` in your tests, you can use the `@ComponentScan(basePackages = \"...\")` annotation:\n\n``` java\npublic class MyTest {\n    \n    // ...\n\n    @Configuration\n    @ComponentScan(basePackages = \"ch.lihsmi.spring.amqp.byexample.exchanges.direct\")\n    public static class TestConfiguration {\n\n        // ...\n\n    }\n\n    @Component\n    public static class TestMessageListener {\n\n        // ...\n\n    }\n    \n}\n```\n","encoding":"utf-8"}},"public":true,"created_at":"2016-10-04T11:02:57Z","updated_at":"2022-10-22T19:21:22Z","description":"Spring Boot Testing","comments":1,"user":null,"comments_enabled":true,"comments_url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/comments","owner":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"forks":[{"url":"https://api.github.com/gists/c37afbfe2152f55e8fba9cb21da04962","user":{"login":"vinnyvoffice","id":6085271,"node_id":"MDQ6VXNlcjYwODUyNzE=","avatar_url":"https://avatars.githubusercontent.com/u/6085271?v=4","gravatar_id":"","url":"https://api.github.com/users/vinnyvoffice","html_url":"https://github.com/vinnyvoffice","followers_url":"https://api.github.com/users/vinnyvoffice/followers","following_url":"https://api.github.com/users/vinnyvoffice/following{/other_user}","gists_url":"https://api.github.com/users/vinnyvoffice/gists{/gist_id}","starred_url":"https://api.github.com/users/vinnyvoffice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinnyvoffice/subscriptions","organizations_url":"https://api.github.com/users/vinnyvoffice/orgs","repos_url":"https://api.github.com/users/vinnyvoffice/repos","events_url":"https://api.github.com/users/vinnyvoffice/events{/privacy}","received_events_url":"https://api.github.com/users/vinnyvoffice/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"Vinícius Rodrigues Nunes","company":"Virtual Office Treinamentos","blog":"www.voffice.com.br","location":"Florianópolis - SC","email":"vinny@voffice.com.br","hireable":null,"bio":"* Java Trainer since 2006\r\n* Java Developer since 2000\r\n* Agile Developer since 2010","twitter_username":null,"public_repos":0,"public_gists":22,"followers":26,"following":52,"created_at":"2013-12-02T11:50:56Z","updated_at":"2026-07-20T11:45:06Z"},"id":"c37afbfe2152f55e8fba9cb21da04962","created_at":"2017-10-29T22:38:31Z","updated_at":"2017-10-29T22:38:31Z"},{"url":"https://api.github.com/gists/3243c7e58874688d7dc8f1bcce0ffe21","user":{"login":"ttekun","id":3950863,"node_id":"MDQ6VXNlcjM5NTA4NjM=","avatar_url":"https://avatars.githubusercontent.com/u/3950863?v=4","gravatar_id":"","url":"https://api.github.com/users/ttekun","html_url":"https://github.com/ttekun","followers_url":"https://api.github.com/users/ttekun/followers","following_url":"https://api.github.com/users/ttekun/following{/other_user}","gists_url":"https://api.github.com/users/ttekun/gists{/gist_id}","starred_url":"https://api.github.com/users/ttekun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ttekun/subscriptions","organizations_url":"https://api.github.com/users/ttekun/orgs","repos_url":"https://api.github.com/users/ttekun/repos","events_url":"https://api.github.com/users/ttekun/events{/privacy}","received_events_url":"https://api.github.com/users/ttekun/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"t","company":null,"blog":"","location":"oykoT","email":null,"hireable":null,"bio":"😳","twitter_username":null,"public_repos":16,"public_gists":6,"followers":9,"following":8,"created_at":"2013-03-23T17:31:57Z","updated_at":"2026-04-04T09:00:14Z"},"id":"3243c7e58874688d7dc8f1bcce0ffe21","created_at":"2017-12-11T05:09:39Z","updated_at":"2017-12-11T05:09:40Z"},{"url":"https://api.github.com/gists/57532ca5fe9ebe116d6f173bc7cc1efd","user":{"login":"tomkul","id":11430389,"node_id":"MDQ6VXNlcjExNDMwMzg5","avatar_url":"https://avatars.githubusercontent.com/u/11430389?v=4","gravatar_id":"","url":"https://api.github.com/users/tomkul","html_url":"https://github.com/tomkul","followers_url":"https://api.github.com/users/tomkul/followers","following_url":"https://api.github.com/users/tomkul/following{/other_user}","gists_url":"https://api.github.com/users/tomkul/gists{/gist_id}","starred_url":"https://api.github.com/users/tomkul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomkul/subscriptions","organizations_url":"https://api.github.com/users/tomkul/orgs","repos_url":"https://api.github.com/users/tomkul/repos","events_url":"https://api.github.com/users/tomkul/events{/privacy}","received_events_url":"https://api.github.com/users/tomkul/received_events","type":"User","user_view_type":"public","site_admin":false,"name":null,"company":null,"blog":"","location":null,"email":null,"hireable":null,"bio":null,"twitter_username":null,"public_repos":19,"public_gists":14,"followers":1,"following":1,"created_at":"2015-03-11T20:25:21Z","updated_at":"2024-03-17T16:07:28Z"},"id":"57532ca5fe9ebe116d6f173bc7cc1efd","created_at":"2018-11-06T10:04:05Z","updated_at":"2018-11-06T10:04:25Z"}],"history":[{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"a193be33a5c41375e1e0a0664d54cd10937bd583","committed_at":"2016-10-07T20:31:21Z","change_status":{"total":30,"additions":29,"deletions":1},"url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/a193be33a5c41375e1e0a0664d54cd10937bd583"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"2c4d9e510a4c7eb5c1de67e9812886ea0fa394f4","committed_at":"2016-10-04T11:22:35Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/2c4d9e510a4c7eb5c1de67e9812886ea0fa394f4"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"8d554d533a8c47044ee127dd2a738b29443b93d4","committed_at":"2016-10-04T11:21:17Z","change_status":{"total":24,"additions":23,"deletions":1},"url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/8d554d533a8c47044ee127dd2a738b29443b93d4"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"22c626000e6d647a7d7fa660e56fec1b357a07df","committed_at":"2016-10-04T11:02:57Z","change_status":{"total":15,"additions":15,"deletions":0},"url":"https://api.github.com/gists/3dcaaf3cf6cbbf18f88728ec78dc7230/22c626000e6d647a7d7fa660e56fec1b357a07df"}],"truncated":false}