Idiomatic way to use a downloaded project as test base fixture

Answered

Hi community, it's me again.

So, in relation to the problem in this thread, i have a problem :

the class i need (GenericValue) is inside the OFBiz project. This project doesn't have a maven package, or any easilly accessible lib.

So i'm a little stuck. My idea is the following :

i could try to download the latest release of OFBiz, ans use this downloaded project as a fixture project.

My question is the following : How can i setup the downloaded project as my test fixture project ?

i thought about using

protected void setUp() {
super.setUp()
myFixture.copyDirectoryToProject(/*just past the whole thing*/)
}

But it doesn't feel right.

Is the whole thing possible ? and if it is, what would be the most idiomatic way of doing so ?

I posted a question on the IDEA Slack, but i thought that a bit more info was needed

0
2 comments

Hi Gaëtan,

Do I understand correctly that you need the GenericValue class to be resolved in your test project? If this is the main requirement, then it is definitely an overkill to set up the entire project in the test fixture. Also, the test fixture should reflect the test project, so something that your users will actually create in real life, and copying the library sources doesn't seem like a common use case.

If the number of required classes is small and you need just methods/fields to be resolved, I suggest using:

myFixture.addClass("package com.example; public class GenericValue { String someMethod() {} ... }");

and adding the minimal code you need for your tests. This is a valid approach for tests and it makes them fast as it loads the minimal code required by test logic.

If you have to add a lot of classes, then I suggest downloading or building the project to JAR and adding it in your project descriptor:

class Java8ProjectDescriptor() : DefaultLightProjectDescriptor() {

    override fun getSdk(): Sdk = IdeaTestUtil.getMockJdk18()

    override fun setUpProject(project: Project, handler: SetupHandler) {
      super.setUpProject(project, handler)
      runWriteAction {
          val main = ModuleManager.getInstance(project).findModuleByName(LightProjectDescriptor.TEST_MODULE_NAME)!!
          PsiTestUtil.addLibrary(main, "src/test/resources/com/example/ofbiz.jar")
        }
  }
}

The JAR should be placed in the <your-project>/src/test/resources/com/example/ofbiz.jar. The project descriptor should be of course returned from your test's getProjectDescriptor() method.

1

I'm sorry i didn't answer, it's been a while. I worked !
Thank you for your patience (on this topic and others). I don't see where i can mark this resolved though

0

Please sign in to leave a comment.