-
Notifications
You must be signed in to change notification settings - Fork 29
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
add spring support test #45
base: master
Are you sure you want to change the base?
add spring support test #45
Conversation
c9b6bcc
to
8e1f36e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #45 +/- ##
=====================================================
+ Coverage 69.41646% 70.46688% +1.05042%
- Complexity 4125 4220 +95
=====================================================
Files 428 428
Lines 16777 16771 -6
Branches 1698 1698
=====================================================
+ Hits 11646 11818 +172
+ Misses 4030 3863 -167
+ Partials 1101 1090 -11
|
4222e3f
to
84703c3
Compare
|
||
@Test | ||
public void testContextLoads() { | ||
// 测试上下文加载 |
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.
统一使用英文注释,下面也是
@Test | ||
public void testParseCallInfoWithIllegalArgument() { | ||
try { | ||
TrpcGatewayClient.parseCallInfo("http://www.abc.com"); |
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.
可以对解析后的内容进行断言
public void setUp() { | ||
config = mock(Config.class); | ||
factory = new TrpcGatewayFilterFactory(); | ||
ReflectionTestUtils.setField(factory, "requestRewriter", mock(TrpcRequestRewriter.class)); |
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.
建议减少使用反射,可以搭建客户端服务端进行单测
|
||
@Test | ||
public void testLoadRequestRewriterWithNull() { | ||
String className = "com.tencent.trpc.spring.cloud.gateway.filter.request.MyRequestRewriterTest"; |
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.
代码中的字符串建议提取为常量
@@ -32,17 +31,6 @@ public class DefaultExceptionResultTransformer implements ExceptionResultTransfo | |||
|
|||
private static final Map<Class<? extends Message>, Builder> cache = new ConcurrentHashMap<>(); | |||
|
|||
private static <T extends Message> Builder newBuilder(Class<T> clazz) { |
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.
这里建议先保留
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class PluginsSchemaTest { |
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.
trpc-spring-support/trpc-spring/src/test/java/com/tencent/trpc/spring/context下面的单测不太符合预期,建议再增加一个单测:启动一个trpc-java服务,有trpc相关配置文件,再去断言配置服务正确读取、解析,插件是否注册成功,以及客户端和服务端正常请求和回包
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class HandleExceptionConfigurerTest { |
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.
建议增加真实的rpc调用,去触发异常捕获,以及断言
Assert.assertEquals(Integer.valueOf(eleNumberValue), resolvedAttributes.get(eleNumberKey)); | ||
} | ||
|
||
// 测试resolvePlaceholders处理字符串数组的情况 |
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.
英文注释,以及需要注意一下注释的格式
linked #34
单测覆盖率链接