最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【规避解决】VSCode中调试java报错:Error The resource projects/�u5�/src java is not testable

Java crifan 1807浏览 0评论
折腾:
【已解决】Mac中用VSCode调试java代码
期间,VSCode中调试java报错:
Error: The resource: /Users/crifan/dev/dev_root/projects/�u5�/src/refer/java/iec_analysis/src/test/java/com/iec/test/Analysis104Test.java is not testable.
来源:Java Test Runner (扩展)
很明显,路径中,包含的中文 无法正常显示
-》要么想办法让其支持中文
-》要么:还是把文件夹改为英文吧
还是去把文件夹从中文改为英文。
暂时规避了此问题。
但是想要彻底解决
所以再去改为中文:
然后复现此问题:
vscode java  is not testable
vscode java Error The resource is not testable
vscode java path contain non-ascii Error The resource is not testable
Path with non-ASCII characters won’t hit breakpoints · Issue #688 · microsoft/vscode-python · GitHub
看到了,此处是:
Java Test Runner
不支持路径中的中文
vscode Java Test Runner path  non-ascii  not testable
  Java Test Runner path non-ascii  not testable
Java Test Runner path non-ascii
vscode Java Test Runner
Java test runner did not run test and always shows skipped. · Issue #208 · microsoft/vscode-java-test · GitHub
Java Test Runner – Visual Studio Marketplace
看看配置中,能否设置路径支持非ascii
Run with Configuration · microsoft/vscode-java-test Wiki · GitHub
没看到这方面的设置
或许:路径不支持中文 是java本身的问题?
vscode java non ascii path
Issues · microsoft/vscode-java-debug · GitHub
Non-ASCII char support for Windows terminals · Issue #622 · microsoft/vscode-java-debug · GitHub
此处输出是:
Java Test Runner
输出的
不是其他的,比如maven等
VSCode Java Debug Console in Terminal Not Showing Unicode Characters · Issue #524 · microsoft/vscode-java-debug · GitHub
“VSCode Terminal being started is using the default Windows code page of 65000, which is ASCII, not 65001 which is UTF-8.”
和此问题相关
VSCode Debug Console
或许可以把console,换成外部终端,就可以支持此处的中文了?
Use a bat launcher to set page code by Eskibear · Pull Request #625 · microsoft/vscode-java-debug · GitHub
此处是:vscode-java-debug,貌似修复了bug
但是此处的
Java Test Runner
还是不支持的
vscode 报:Classpath is incomplete的解决方法_awesomeQ的专栏-CSDN博客
此处没法去设置
.vscode/launch.json
因为不是通过其中的configurations的配置去调试的,而是点击了junit的类的Debug Test去启动调试的
java test runner github
VSCode中的Java Test Runner,就是github中的
GitHub – microsoft/vscode-java-test: Run and debug Java test cases in Visual Studio Code.
对于Java Test Runner输出的:
Error The resource xxx is not testable
下载源码,去搜索看,其内部处理过程
不过网上可以搜索到:
java test runner Error The resource “is not testable”
refactor: Allow the test runner to accept the debug launch configuration by jdneo · Pull Request #801 · microsoft/vscode-java-test · GitHub
 11  ....test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchUtils.java 


 @@ -13,6 +13,7 @@


import com.google.gson.Gson;
import com.microsoft.java.test.plugin.launchers.JUnitLaunchConfigurationDelegate.JUnitLaunchArguments;
import com.microsoft.java.test.plugin.model.TestLevel;


import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
 @@ -56,14 +57,14 @@ public static JUnitLaunchArguments resolveLaunchArgument(List<Object> arguments,
        }
        info.project = javaProject.getProject();


        if (args.runFromRoot) {
        if (args.scope == TestLevel.ROOT || args.scope == TestLevel.FOLDER) {
            info.testContainer = StringEscapeUtils.escapeXml(javaProject.getHandleIdentifier());
        } else {
            final File file = Paths.get(new URI(args.uri)).toFile();
            if (file.isFile()) {
                parseConfigurationInfoForClass(info, args);
            } else if (file.isDirectory()) {
            if (args.scope == TestLevel.PACKAGE && file.isDirectory()) {
                parseConfigurationInfoForContainer(info, args);
            } else if ((args.scope == TestLevel.CLASS || args.scope == TestLevel.METHOD) && file.isFile()) {
                parseConfigurationInfoForClass(info, args);
            } else {
                throw new RuntimeException("The resource: " + file.getPath() + " is not testable.");
            }
test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchUtils.java
中的resolveLaunchArgument中,判断不符合条件,才报错的
throw new RuntimeException("The resource: " + file.getPath() + " is not testable.");
下载完代码了:
➜  java git clone https://github.com/microsoft/vscode-java-test.git
Cloning into 'vscode-java-test'...
remote: Enumerating objects: 140, done.
remote: Counting objects: 100% (140/140), done.
remote: Compressing objects: 100% (90/90), done.
remote: Total 5978 (delta 54), reused 82 (delta 33), pack-reused 5838
Receiving objects: 100% (5978/5978), 7.53 MiB | 39.00 KiB/s, done.
Resolving deltas: 100% (3451/3451), done.
去看看代码
java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchUtils.java

public class JUnitLaunchUtils {


    private static final String TESTNG_LOADER = "com.microsoft.java.test.loader.testng";
    private static final String JUNIT5_LOADER = "org.eclipse.jdt.junit.loader.junit5";
    private static final String JUNIT4_LOADER = "org.eclipse.jdt.junit.loader.junit4";


    private JUnitLaunchUtils() {}


    public static JUnitLaunchArguments resolveLaunchArgument(List<Object> arguments, IProgressMonitor monitor)
            throws URISyntaxException, CoreException {
        final Gson gson = new Gson();
        final Argument args = gson.fromJson((String) arguments.get(0), Argument.class);


        final TestInfo info = new TestInfo();


        info.testKind = getEclipseTestKind(args.testKind);


        final IJavaProject javaProject = ProjectUtils.getJavaProject(args.project);
        if (javaProject == null || !javaProject.exists()) {
            throw new RuntimeException("Failed to get the project with name: " + args.project);
        }
        info.project = javaProject.getProject();


        if (args.scope == TestLevel.ROOT || args.scope == TestLevel.FOLDER) {
            info.testContainer = StringEscapeUtils.escapeXml(javaProject.getHandleIdentifier());
        } else {
            final File file = Paths.get(new URI(args.uri)).toFile();
            if (args.scope == TestLevel.PACKAGE && file.isDirectory()) {
                parseConfigurationInfoForContainer(info, args);
            } else if ((args.scope == TestLevel.CLASS || args.scope == TestLevel.METHOD) && file.isFile()) {
                parseConfigurationInfoForClass(info, args);
            } else {
                throw new RuntimeException("The resource: " + file.getPath() + " is not testable.");
            }
        }
看起来很像是:
final File file = Paths.get(new URI(args.uri)).toFile();
估计此处URI或path不支持中文路径。
java URI path non ascii
android – Java – how to encode URL path for non Latin characters – Stack Overflow
encoding – URL decoding in Java for non-ASCII characters – Stack Overflow
java – Illegal characters in URI – Stack Overflow
去看看args.uri
java args.uri
final Gson gson = new Gson();
final Argument args = gson.fromJson((String) arguments.get(0), Argument.class);

final File file = Paths.get(new URI(args.uri)).toFile();
java gson non ascii
java – GSON – Not escaping unicode char – Stack Overflow
Enable Escape All Non Ascii chars · Issue #388 · google/gson · GitHub
json – Gson Unicode characters conversion to Unicode character codes – Stack Overflow
java – How to ensure that Gson’s output in toJson() is ASCII? – Stack Overflow
java – GSON not sending in UTF-8 – Stack Overflow
据说是:gson不支持unicode,即此处不支持非ascii的中文
gson fromJson non ascii
Java下json的解析方法—–GSON与JSONObject_lrenjundk的专栏-CSDN博客
gson fromJson non unicode
java – Can someone clarify Gson’s unicode encoding? – Stack Overflow
java – GSON – use unicode characters – Stack Overflow
java – gson serialization of unicode string not working – Stack Overflow
Gson fails to parse strings with chinese characters · Issue #23 · google/gson · GitHub
https://github.com/google/gson/issues/23
chinese question – Google Groups
Is that gson not support non-English charaterset – Google Groups
算了,此处不再去深究了。
总之是:
【总结】
VSCode中,此处点击JUnit的类的Debug Test,会报错:
Error: The resource: /Users/crifan/dev/dev_root/projects/�u5�/src/refer/java/iec_analysis/src/test/java/com/iec/test/Analysis104Test.java is not testable.
来源:Java Test Runner (扩展)
原因是:
此处的路径,包含中文:铜陵电力
然后内部用的是Java Test Runner
相关报错代码是:
GitHub – microsoft/vscode-java-test: Run and debug Java test cases in Visual Studio Code.
java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchUtils.java

public class JUnitLaunchUtils {


    private static final String TESTNG_LOADER = "com.microsoft.java.test.loader.testng";
    private static final String JUNIT5_LOADER = "org.eclipse.jdt.junit.loader.junit5";
    private static final String JUNIT4_LOADER = "org.eclipse.jdt.junit.loader.junit4";


    private JUnitLaunchUtils() {}


    public static JUnitLaunchArguments resolveLaunchArgument(List<Object> arguments, IProgressMonitor monitor)
            throws URISyntaxException, CoreException {
        final Gson gson = new Gson();
        final Argument args = gson.fromJson((String) arguments.get(0), Argument.class);


        final TestInfo info = new TestInfo();


        info.testKind = getEclipseTestKind(args.testKind);


        final IJavaProject javaProject = ProjectUtils.getJavaProject(args.project);
        if (javaProject == null || !javaProject.exists()) {
            throw new RuntimeException("Failed to get the project with name: " + args.project);
        }
        info.project = javaProject.getProject();


        if (args.scope == TestLevel.ROOT || args.scope == TestLevel.FOLDER) {
            info.testContainer = StringEscapeUtils.escapeXml(javaProject.getHandleIdentifier());
        } else {
            final File file = Paths.get(new URI(args.uri)).toFile();
            if (args.scope == TestLevel.PACKAGE && file.isDirectory()) {
                parseConfigurationInfoForContainer(info, args);
            } else if ((args.scope == TestLevel.CLASS || args.scope == TestLevel.METHOD) && file.isFile()) {
                parseConfigurationInfoForClass(info, args);
            } else {
                throw new RuntimeException("The resource: " + file.getPath() + " is not testable.");
            }
        }
出错的具体原因:
最大可能是
final Argument args = gson.fromJson((String) arguments.get(0), Argument.class);
gson的fromJson,对于非ascii的中文,不是unicode字符串,解析有问题
其次可能是:
final File file = Paths.get(new URI(args.uri)).toFile();
中的Paths或URI,对于中文支持不好。
暂时,没精力去研究。
暂时:只能把路径里的中文,改为英文,规避问题。

转载请注明:在路上 » 【规避解决】VSCode中调试java报错:Error The resource projects/�u5�/src java is not testable

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.185 seconds, using 22.15MB memory