JUnit 对类名有一些奇怪的 30 个字符长度限制吗?
我有一个为一些单元测试编写的课程。一切都进展顺利,直到我更改了类的名称以匹配我正在测试的带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
默认情况下,我相信 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.
事实证明,这是因为我扩展了 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.
检查运行 -> 下的运行配置跑步...
您的测试在那里有一个配置。检查“测试类别”字段。
Check your run Configuration under Run -> Run...
Your Test has a Configuration there. Check the "Test class" field.
我不确定这是否与某种操作系统长度限制有关,而是与:
事实上,您的消息看起来像:
来自 快速提示:JUnit:启动配置的输入类型不存在
可能存在长度限制问题(您可以看到一些项目正在进行重构“以低于文件长度限制”(
org.eclipse.jdt.core.tests.performance
)。但这很奇怪,考虑到 Windows 上的长度限制:
CreateProcess
函数的最大命令行长度为32767 个字符。此限制来自于核心函数 UNICODE_STRING 结构。用于创建进程,因此如果您直接与 Win32 对话,那么这是您需要担心的唯一限制,但如果您通过其他方式到达 CreateProcess,那么您所经历的路径可能有其他限制ShellExecute/Ex
函数施加的INTERNET_MAX_URL_LENGTH
(大约 2048)命令行长度限制,2048 长度。 (如果您在 Windows 95 上运行,则限制仅为MAX_PATH
。)也许 javac 命令的总长度确实超出了这些限制之一,并且无法编译这些 JUnit Java 类之一,这意味着无法再执行(并触发上述错误消息)
I am not sure this is linked at all to some kind of OS length limitation, but rather to:
Indeed, you message looks like:
From QuickTip: JUnit: The input type of the launch configuration does not exist
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:
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.INTERNET_MAX_URL_LENGTH
(around 2048) command line length limit imposed by theShellExecute/Ex
functions. (If you are running on Windows 95, then the limit is onlyMAX_PATH
.)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)