Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chenhao26-nineteen
Copy link
Contributor

@chenhao26-nineteen chenhao26-nineteen commented Jun 11, 2024

@chenhao26-nineteen chenhao26-nineteen force-pushed the feat/add-spring-support-test02 branch from c9b6bcc to 8e1f36e Compare June 11, 2024 09:46
Copy link

codecov bot commented Jun 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.46688%. Comparing base (e72139d) to head (da67d49).

Additional details and impacted files

Impacted file tree graph

@@                  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     
Files Coverage Δ
...ion/support/DefaultExceptionResultTransformer.java 100.00000% <ø> (+27.27272%) ⬆️

... and 20 files with indirect coverage changes

@chenhao26-nineteen chenhao26-nineteen force-pushed the feat/add-spring-support-test02 branch from 4222e3f to 84703c3 Compare June 12, 2024 14:04

@Test
public void testContextLoads() {
// 测试上下文加载
Copy link
Collaborator

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");
Copy link
Collaborator

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));
Copy link
Collaborator

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";
Copy link
Collaborator

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) {
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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处理字符串数组的情况
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文注释,以及需要注意一下注释的格式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants