折腾:
【已解决】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
看看配置中,能否设置路径支持非ascii
没看到这方面的设置
或许:路径不支持中文 是java本身的问题?
vscode java non ascii path
此处输出是:
Java Test Runner
输出的
不是其他的,比如maven等
“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,换成外部终端,就可以支持此处的中文了?
此处是:vscode-java-debug,貌似修复了bug
但是此处的
Java Test Runner
还是不支持的
此处没法去设置
.vscode/launch.json
因为不是通过其中的configurations的配置去调试的,而是点击了junit的类的Debug Test去启动调试的
java test runner github
VSCode中的Java Test Runner,就是github中的
对于Java Test Runner输出的:
Error The resource xxx is not testable
下载源码,去搜索看,其内部处理过程
不过网上可以搜索到:
java test runner Error The resource “is not testable”
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
去看看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
据说是:gson不支持unicode,即此处不支持非ascii的中文
gson fromJson non ascii
gson fromJson non unicode
Gson fails to parse strings with chinese characters · Issue #23 · google/gson · GitHub
算了,此处不再去深究了。
总之是:
【总结】
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
相关报错代码是:
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