How to get project side files in tests


I am writing unit tests for my plugin, in which i am getting pom.xml file of user's project in psi file and later casting it to xml file. How can i get this file in tests?

评论操作 固定链接

I'm sorry I don't understand what the problem is. Please share your code or more details about your current test setup and what does not work exactly.

评论操作 固定链接

class POMXMLTest extends BasePlatformTestCase {

  protected String getTestDataPath() {
    return "src/test/java/demo/testdata";
  void getfileTest() throws IOException {
    File file = new File("src/test/java/demo/testdata/correctpom.xml");
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName("pom.xml");
    String content = Files.asCharSource(file, Charsets.UTF_8).read();
    PsiFile files =createLightFile(fileType, content);

    POMXML pom = new POMXML();
   // DependencyDetails dependencyDetails = pom.getfile(fi);
    // List<String> artifactIdListTest =
    //     Arrays.asList("asm-util", "sisu-inject-bean", "parboiled-java", "xercesImpl");
    // List<String> groupIdListTest =
    //     Arrays.asList("org.ow2.asm", "org.sonatype.sisu", "org.parboiled", "xerces");
    // List<String> versionListTest = Arrays.asList("4.1", "1.4.2", "1.1.4", "2.9.1");

    Assert.assertEquals(1, 1);
    // Assertions.assertTrue(
    //     Iterables.elementsEqual(dependencyDetails.artifactIdList, artifactIdListTest));
    // Assertions.assertTrue(Iterables.elementsEqual(dependencyDetails.groupIdList,
    // groupIdListTest));
    // Assertions.assertTrue(Iterables.elementsEqual(dependencyDetails.versionList,
    // versionListTest));


评论操作 固定链接

This code is throwing NullPointerException at line PsiFile files = createLightFile 

评论操作 固定链接

Please use provided methods from test fixture to create and add files to the test environment. There's usually no reason to manually use anything like Java's File API at all. See