views:

210

answers:

1

I have generated a new Scala project with Maven and it created a folder structure with a src/main/scala and a src/test/scala folder. I have some code in src/main/scala and wanted to write some tests, the problem is that I can't import the classes from src/main/scala. How do I do that?

+1  A: 

May be I'm misunderstanding this, but ideally you would have your tests in the same package as the source class you're testing, so you don't have to import them.

Maven should make sure that your sources are seen by the test classes during the test phase. The sources (src/main/scala) were built during the compile phase and placed into target/classes and the tests (src/test/scala) are build under test-compile and placed under target/test-classes. During the test phase maven should make sure that both target/classes and target/test-classes are on the classpath when it runs the tests.

Look under target and peruse the structure under there - it tells a story - that is the result of what maven does.

George
That's what I thought but the test doesn't compile
Alexander Stolz
Ok I've found the error. The classes had wrong package declarations, a copy and paste error from migrating the project to maven
Alexander Stolz