0

I'm facing a problem with JUnit tests. I have written an JUnitRunner which is used to execute the WrapperTest.

The WrapperTest generates a plain JUnit-Test and a needed file. If I want to execute the methods of the generated test, my Runner searchs in the Developement-Workspace for the "NeededClass".

I'm generating the needed class in the JUnit-Workspace and i want the tests to use this generated class file, so i can delete this file in my Develop-Workspace.

So, how do I execute the generated test in the JUnit-Workspace? (He shall look in the JUnit-Workspace for the needed file)enter image description here

edit: OK, i found out, it's a ClassLoader problem... The Develop Workspace got another ClassLoader than the JUnit-Workspace, this causes weired errors, for example that a "class isn't the identical class Exception" (java.lang.ClassCastException: org.junit.runner.JUnitCore cannot be cast to org.junit.runner.JUnitCore). Looks like i have to fix this problem by reflection, what is very dirty.

SWYM
  • 43
  • 1
  • 8

1 Answers1

-1

Look into Maven and its build lifecycle. You can wire the code generation you are doing into the generate-test-sources phase and then have it participate as normal in the test phase.

See this question for an example.

Community
  • 1
  • 1
Adriaan Koster
  • 15,870
  • 5
  • 45
  • 60
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Airsource Ltd Jan 15 '15 at 14:34
  • I provided an answer roughly with the same level of detail OP provided in the question. – Adriaan Koster Jan 15 '15 at 14:40
  • So what? It's still a link-only answer in the sense that you haven't explained how to do anything - and if the link changes, the answer becomes useless. – Airsource Ltd Jan 15 '15 at 14:43
  • The link is not that important for my answer. The key element is looking into the Maven build lifecycle to wire up code generation in a way it can be tested. Even though my answer is short does not mean there is anything wrong with it. If OP had provided more detail in the question I could have given a more detailed answer. As it stands, answering in more detail is likely to miss the mark. – Adriaan Koster Jan 15 '15 at 14:49
  • We'll have to agree to differ. Just FTR, I have not voted your answer down. – Airsource Ltd Jan 15 '15 at 14:53
  • Fair enough. Thanks for the feedback. – Adriaan Koster Jan 15 '15 at 15:13