Rsaleh
Rsaleh

Reputation: 87

Can't import a java package in another

I'm using selenium web driver with TestNG framework and NetBeans IDE. Simply I want to import ExercisesTestCode package in the ExercisesSourceCode.

import ExercisesTestCode.*;

It says Package ExercisesTestCode does not exist. How can I fix this? Notice I can import ExercisesSourceCode package in ExercisesTestCode. enter image description here

Upvotes: 0

Views: 783

Answers (2)

Vijay Chavda
Vijay Chavda

Reputation: 862

You want to import your test code in your source code...

Usually Test code is meant to "test" your source code!

So it makes no sense why would you want to do such a thing. Build tool wont allow you this in the first place.

What you need to do is: Place the code in Test code which you are referencing into source codes. Or second (not the best, but will solve your problem) option is to create a package named 'test' inside your source package.

Upvotes: 0

byxor
byxor

Reputation: 6349

Your test packages won't be compiled along with your main source code. This is done by your build tool to save space since your program doesn't need the tests after it has been built.

This means you cannot access the code in your Test Package from your main source code.

How can I fix this?

It sounds like you've put some of your code in the wrong place. By moving whatever logic you need into your Source Package, you will be able to access it from both your tests and your main program.

Upvotes: 2

Related Questions