1

This might be a silly question, but I need to know. I'll delete it if it's too silly to answer.

In a maven project in IntelliJ, I have the following structure:

procedure
   e2e
      cucumber (same level as common)
         src
            test
               java
                  e2e
                     support
                        File: ScenarioState.java
                              package e2e.support

      common (same level as cucumber)
         src
            main
               java
                  common
                     testdata
                        File: Case.java
                              package common.testdata

Is there any way to import the package e2e.support (where ScenarioState.java resides) into the file Case.java in the common.testdata package?

I've been playing around with maven imports, dependencies etc., but I haven't found a way to do it. I might have to redesign some classes to get around it, but that would impact other parts of the project and I'd like to avoid it if possible.

  • 1
    Maybe, but it really looks like a bad idea. You should never import test classes into main classes. – J Fabian Meier Oct 24 '19 at 14:09
  • I agree in principle. However, this project is in it's entirety a test automation project. Where the classes are placed doesn't necessarily reflect "test" or "main" funcitonality. The ScenarioState class is an object used by the test to store state during the each test run. –  Oct 25 '19 at 07:08
  • If the entire project is for test automation, it should have all classes in `src/main/java`. Unless, of course, you want to test the test automation ;-). – J Fabian Meier Oct 25 '19 at 07:20
  • Yes, the organization could probably be better. However, I wasn't created by me, and restructuring the whole project is not within my scope at this time. –  Oct 25 '19 at 07:34

2 Answers2

0

If you really want to do that (and I would strongly recommend to either leave the project alone or restructure it first), define an additional source directory as in

How to add an extra source directory for maven to compile and include in the build jar?

But beware that a project like this will haunt you till the end of time.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

One could have in the common's pom.xml a dependency to cucumber with <type>test-jar</type>.

However this violates the concept of src/main for the final product, and src/test for the unit-tests (not incorporated in the product, separate test classes).

(In src/test there can be other classes, so maybe easiest would be for common to have a src/test instead.)

If ScenarioState has nothing to do in src/main, one could place it in a more low-level library cucumberbase in src/main. And make a dependency in cucumber to cucumberbase with <scope>test</scope>. In <common> a normal dependency to cucumberbase.

Keep this main-test separation as otherwise other developers risk insanity.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138