Access PSIFile or PSIDirectory from JUnit Test
I'm working with the PSI parser in Intellij and want to test output on a large set of files with JUnit testing. I need to access the PSI Files from with int the JUnit setUp() method.
I've tried to access my test directory as a PSIDirectory with the following code:
DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();
assert dataContext != null;
this.project = DataKeys.PROJECT.getData(dataContext);
assert this.project != null;
PsiDirectory baseDirectory = PsiManager.getInstance(this.project).findDirectory(this.project.getBaseDir());
this.testDirectory = baseDirectory.findSubdirectory("tests");
But this doesn't seem to work because DataManager.getInstance() fails. Is there a way to access PSIDirectories from a JUnit test? I think I need the active project but I can't find out how to access it.
请先登录再写评论。
Hi,
do you have PlatformTestCase as a superclass? In it's setup the test application is loaded so you can call application components and the rest stuff.
Anna