JUnit 对类名有一些奇怪的 30 个字符长度限制吗?

发布于 2024-08-05 11:58:52 字数 442 浏览 8 评论 0原文

我有一个为一些单元测试编写的课程。一切都进展顺利,直到我更改了类的名称以匹配我正在测试的带有 TestCase 后缀的类。突然间,每次我尝试在 Eclipse 中运行测试用例时,我都会收到“没有此类型的输入配置”。

然后有人建议类名的长度限制为 30 个字符。我看了一下类名,有32个字符长。然后我删除了末尾的两个字符并再次尝试,一切正常。我把它们放回去,它就停止工作了。

对此有解释吗?

编辑:

回应一些评论。它是 Galileo,使用 Windows XP、JUnit 4.4。

编辑2:

抱歉各位。我想我错了。该模式似乎是 JUnit/Eclipse 不喜欢我的类名是 TestCase。一旦我把测试用例部分拿走,它就可以工作了。它适用于超长弦、短弦以及介于两者之间的所有弦。名称可以是 ABCTestCase 之类的任何名称,但由于某种原因不能是 TestCase。

I have a class that I made for some unit tests. Everything was going swimmingly until I changed the name of the class to match the class that I was testing suffixed with TestCase. All of a sudden every time I tried to run the test case in Eclipse I get a "There is no input configuration for this type".

Someone then suggested that there is a 30 character length limit on the name of the class. I had a look at the class name and it was 32 characters long. I then deleted two characters off the end and tried again and everything worked. I put them back and it stopped working.

Is there an explanation for this?

EDIT:

In response to some of the comments. It is Galileo, using Windows XP, JUnit 4.4.

EDIT 2:

Sorry guys. I guess I was wrong. The pattern seems to be that JUnit/Eclipse does not like my class name being TestCase. As soon as I take the TestCase part away it works. It works with a massively long string, short strings and everything in between. The name can be anything like ABCTestCase it just CANNOT be for some reason TestCase.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爱冒险 2024-08-12 11:58:52

默认情况下,我相信 JUnit 运行程序设置为查找 *Test 文件,因此它将过滤掉 TestCase。人们经常使用 *TestCase 作为基类,而不进行任何自己的测试。不确定这是否是您遇到的情况。如果是这样,则可以在运行器中对其进行配置。

By default I believe the JUnit runners are set to look for *Test files, so it will filter out TestCase. People often use *TestCase as a base class without any tests of its own. Not sure if that's what you're running into. If so, it's configurable in the runner.

So要识趣 2024-08-12 11:58:52

事实证明,这是因为我扩展了 TestCase,这使得 JUnit 运行程序认为它仍然是版本 3。即使你告诉它使用版本 4。

Turns out that it was because I was extending TestCase which makes the JUnit runner think it is still version 3. Even if you tell it to use version 4.

看海 2024-08-12 11:58:52

检查运行 -> 下的运行配置跑步...
您的测试在那里有一个配置。检查“测试类别”字段。

Check your run Configuration under Run -> Run...
Your Test has a Configuration there. Check the "Test class" field.

夜未央樱花落 2024-08-12 11:58:52

我不确定这是否与某种操作系统长度限制有关,而是与:

  • 一些基于类名称的硬编码参数化有关。
  • 或者源文件夹出现一些问题。
    事实上,您的消息看起来像:

alt text

来自 快速提示:JUnit:启动配置的输入类型不存在

如果您在运行测试用例时在 Eclipse IDE 中收到上述错误消息,只需确保您将测试类作为“eclipse 源文件夹”定义的一部分即可。

最简单的方法。右键单击文件夹->构建路径 –>用作源文件夹


可能存在长度限制问题(您可以看到一些项目正在进行重构“以低于文件长度限制”(org.eclipse.jdt.core.tests.performance)。

但这很奇怪,考虑到 Windows 上的长度限制:

  • CreateProcess 函数的最大命令行长度32767 个字符。此限制来自于核心函数 UNICODE_STRING 结构。用于创建进程,因此如果您直接与 Win32 对话,那么这是您需要担心的唯一限制,但如果您通过其他方式到达 CreateProcess,那么您所经历的路径可能有其他限制
  • CMD.EXE 施加的字符命令行长度限制。
  • 由于 ShellExecute/Ex 函数施加的 INTERNET_MAX_URL_LENGTH(大约 2048)命令行长度限制,2048 长度。 (如果您在 Windows 95 上运行,则限制仅为 MAX_PATH。)
  • 环境的最大大小32767 个字符(包括所有变量名加上所有值)

也许 javac 命令的总长度确实超出了这些限制之一,并且无法编译这些 JUnit Java 类之一,这意味着无法再执行(并触发上述错误消息)

I am not sure this is linked at all to some kind of OS length limitation, but rather to:

  • some hard-coded parametrization based on the name of the class.
  • or to some problem with the source folder.
    Indeed, you message looks like:

alt text

From QuickTip: JUnit: The input type of the launch configuration does not exist

If you are getting the above error message in Eclipse IDE, while running your test case, just make sure that you have the test class as a part of the “eclipse source folder” definition.

Easiest way. Right click on the folder –> Build Path –>Use as source folder


There could be a length limit issue (you can see some projects undergoing a refactoring "to be under the file length limit" (org.eclipse.jdt.core.tests.performance).

But that is strange, considering the length limit on Windows are:

  • 32767 characters for the maximum command line length for the CreateProcess function. This limitation comes from the UNICODE_STRING structure. CreateProcess is the core function for creating processes, so if you are talking directly to Win32, then that's the only limit you have to worry about. But if you are reaching CreateProcess by some other means, then the path you travel through may have other limits.
  • 8192 character command line length limit imposed by CMD.EXE.
  • 2048 length due to the INTERNET_MAX_URL_LENGTH (around 2048) command line length limit imposed by the ShellExecute/Ex functions. (If you are running on Windows 95, then the limit is only MAX_PATH.)
  • 32767 characters for the maximum size of your environment (includes the all the variable names plus all the values)

Maybe the total length of the javac command does exceed one of those limits, and fail to compile one of those JUnit Java classes, meaning it can no longer be executed (and trigger the above error message)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文