我正在尝试测试其中一个具有Vaadin UI参数的类,
在测试执行级别,我有一个空指针异常
String basePath = getBasePath();测试用例无法访问此部分,因为由于NullPointerException而无法访问getBasePath()方法。
protected String getBasePath(){
String basePath = "";
String host = UI.getCurrent().getPage().getLocation().getHost();
int port = UI.getCurrent().getPage().getLocation().getPort();
String path_app = UI.getCurrent().getPage().getLocation().getPath();
String http_s = UI.getCurrent().getPage().getLocation().getScheme();所以在这部分代码中,我测试了
UI.getCurrent().getPage()有一个结果,那么它就不是空的,并且test可以到达它。但是getLocation()有一个空指针异常。
@Before
public void init() throws URISyntaxException, NoSuchFieldException, SecurityException {
TetUI tetUI = new TetUI();
UI.setCurrent(tetUI);
UI.getCurrent().getPage().setLocation("Something");
}我这样设置了位置,或者也可以是一个URI,但它仍然是空的。
我试着在互联网上找到一些关于这个话题的其他来源,但什么也没有出来。
也许我做的方法完全错了,这种方法是正确的吗?有什么建议吗?
发布于 2017-11-12 03:22:45
通过Vaadins静态方法设置值效果不是很好。
您有两个选择:
使用PowerMock.
https://stackoverflow.com/questions/47032894
复制相似问题