简体   繁体   English

G单元测试给出NullPointerException

[英]G unit tests giving NullPointerException

I am using G Unit for the first time for testing Antlr3 grammar but while running the tests, I am getting NullPointerException. 我第一次使用G Unit来测试Antlr3语法,但是在运行测试时,我得到了NullPointerException。

Exception occurs only when there is a method call in the action part of the grammar rule. 仅当语法规则的操作部分中有方法调用时,才会发生异常。

Example: 例:

identifier
: name=ID 
{
obj.identStmt($name.text, this.currentLine, this.currentPos);
}
;

ID: ('a'..'z'|'A'..'Z')+;

While debugging, I get NullPointerException at: 调试时,我在以下位置得到NullPointerException:

obj.identStmt($name.text, this.currentLine, this.currentPos); obj.identStmt($ name.text,this.currentLine,this.currentPos);

I want to know if it is possible to write G unit test case for such a scenario and if yes then how and what I am doing wrong. 我想知道是否可以在这种情况下编写G单元测试用例,如果可以,那么我做错了什么以及做错了什么。

Thanks in advance. 提前致谢。

If i were u , i would use 如果我是你,我会用

        ID : Identifier (Identifier)+;
        Identifier : ('a'..'z'|'A'..'Z');

Just a thought , Your grammar stating that Id ca 只是一个想法,您的语法说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM