-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added side-effect-free stubbing framework for SOFABoot applications #1224
Conversation
…ions With the support of @SofaMockBeanFor and @SofaSpyBeanFor annotations, you can easily mock/spy external dependencies when writing integration tests. More importantly, these annotations does not produce any side-effects, which means that the Spring ApplicationContext can be efficiently cached and reused among different test cases, thus greatly reduce test cost.
Hi @Peng-YM, welcome to SOFAStack community, Please sign Contributor License Agreement! After you signed CLA, we will automatically sync the status of this pull request in 3 minutes. |
This resolves #1172 |
...core/test-sofa-boot/src/main/java/com/alipay/sofa/testing/SofaBootTestAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...core/test-sofa-boot/src/main/java/com/alipay/sofa/testing/SofaBootTestAutoConfiguration.java
Outdated
Show resolved
Hide resolved
sofa-boot-project/sofa-boot-core/test-sofa-boot/src/main/resources/META-INF/spring.factories
Outdated
Show resolved
Hide resolved
sofa-boot-project/sofa-boot-core/test-sofa-boot/src/main/resources/META-INF/spring.factories
Outdated
Show resolved
Hide resolved
...re/test-sofa-boot/src/main/java/com/alipay/sofa/testing/model/definition/StubDefinition.java
Outdated
Show resolved
Hide resolved
...sofa-boot-core/test-sofa-boot/src/main/java/com/alipay/sofa/testing/model/stub/SofaStub.java
Outdated
Show resolved
Hide resolved
...core/test-sofa-boot/src/main/java/com/alipay/sofa/testing/SofaBootTestExecutionListener.java
Outdated
Show resolved
Hide resolved
...core/test-sofa-boot/src/main/java/com/alipay/sofa/testing/SofaBootTestAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...src/main/java/com/alipay/sofa/smoke/tests/integration/test/AnotherExternalServiceClient.java
Outdated
Show resolved
Hide resolved
...ration-test/src/test/java/com/alipay/sofa/smoke/tests/integration/test/MockSofaBeanTest.java
Outdated
Show resolved
Hide resolved
...src/test/java/com/alipay/sofa/smoke/tests/integration/test/base/SofaBootTestApplication.java
Outdated
Show resolved
Hide resolved
Co-authored-by: 致节 <hzj266771@antgroup.com>
...nfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/test/SofaTestAutoConfiguration.java
Outdated
Show resolved
Hide resolved
Major refactor and improvements
Codecov Report
@@ Coverage Diff @@
## master #1224 +/- ##
============================================
- Coverage 84.51% 84.13% -0.39%
- Complexity 2711 2864 +153
============================================
Files 308 323 +15
Lines 8837 9316 +479
Branches 1049 1113 +64
============================================
+ Hits 7469 7838 +369
- Misses 898 973 +75
- Partials 470 505 +35
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -25,6 +25,22 @@ | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-test</artifactId> | |||
</dependency> | |||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime-sofa-boot 和 isle-sofa-boot 设置 true,test 功能和这两个不强耦合
commons-lang3 依赖移除,替换为 spring 自己的工具类
lombok 依赖移除,框架代码不能依赖动态代码生成,需要直接编写相应代码
sofa-boot-tests/pom.xml
Outdated
@@ -22,6 +22,7 @@ | |||
<modules> | |||
<module>sofa-boot-smoke-tests</module> | |||
<module>sofa-boot-jacoco-report</module> | |||
<module>sofa-boot-smoke-tests/sofa-boot-smoke-tests-integration-test</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sofa-boot-smoke-tests-integration-test 应该是 sofa-boot-smoke-tests 的子模块,而不是 sofa-boot-tests
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>runtime-sofa-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只需要保留 runtime-sofa-boot-starter 依赖,和 test-sofa-boot-starter 依赖
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.testing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
包名统一修改为 com.alipay.sofa.test,和spring的风格保持一致,用 test 而不是 testing
* cherrypick:Added side-effect-free stubbing framework for SOFABoot applications #1224 --------- Co-authored-by: 致节 <hzj266771@antgroup.com>
With the support of @SofaMockBeanFor and @SofaSpyBeanFor annotations, you can easily mock/spy external dependencies when writing integration tests. More importantly, these annotations does not produce any side-effects, which means that the Spring ApplicationContext can be efficiently cached and reused among different test cases, thus greatly reduce test cost.