-
Notifications
You must be signed in to change notification settings - Fork 34
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
JUnit中文化的原型验证 #10
Comments
你为啥不把 |
还没来得及看怎么改. 请问你有思路吗? |
In Kotlin we have typealias CESHI = @org.junit.Test or something else. I'm no so sure. I don't know if there's something that can do the same job in Java as the Kotlin code above. |
I've already mentioned the way that can add an alias to an existing name. |
But as far as I'm concerned, all people here know how to declare an annotation. It's commonsense IMO |
暂时没发现Java的类似方法. |
我刚提交了个 commit ,那个 Kotlin 的,我已经告诉你咋整了。另外那个测试方法在 IntelliJ IDEA 中被成功识别。 |
看到了, 多谢. 可惜Java没有这个原生特性. 你有兴趣实现一个中文化的Kotlin测试框架吗? |
关于 @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface 测试{ Class 期待异常() default org.junit.Test.None.class; long 超时() default 0L; } public class CustomRunner extends org.junit.runners.BlockJUnit4ClassRunner{ public CustomRunner(Class klass) throws InitializationError{ super(klass); } @Override protected List computeTestMethods(){ return getTestClass().getAnnotatedMethods(测试.class); } @Override protected void validateTestMethods(List errors){ validatePublicVoidNoArgMethods(测试.class, false, errors); } @Override protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next){ 测试 annotation = method.getAnnotation(测试.class); return expectsException(annotation) ? new ExpectException(next, getExpectedException(annotation)) : next; } @Override protected Statement withPotentialTimeout(FrameworkMethod method, Object test, Statement next){ long timeout = getTimeout(method.getAnnotation(测试.class)); return timeout > 0 ? new FailOnTimeout(next, timeout) : next; } private Class getExpectedException(测试 annotation){ if (annotation == null || annotation.期待异常() == None.class){ return null; }else{ return annotation.期待异常(); } } private boolean expectsException(测试 annotation){ return getExpectedException(annotation) != null; } private long getTimeout(测试 annotation){ if (annotation == null){ return 0; } return annotation.超时(); } } 然后在测试类前加 |
多谢! 一会细看. 感觉可以"立项"了, 新开一个repo继续 :) |
多谢各位提点. 已开https://github.com/program-in-chinese/junit4_in_chinese, 欢迎在那里继续探讨. |
#9 提到的JUnit中文化, 下面是个pretotype:
与中文化前对比:
实现如下:
个人感觉用相对简单的实现, 达到了一定的可读性改进, 还是有意义的. 如果没有意见, 就打算照此思路开始项目了.
The text was updated successfully, but these errors were encountered: