Problem running a test with src/main and src/test - java

Newbie to Java having issue with an existing code base.
It seems Java files in /src/code are not being picked up.
Other devs here use IntelliJ, which runs tests fine out of the box (default config). I'm trying to use VSCode but also get the same result running via the terminal:
Running a test gives me a "cannot find symbol" error trying to import local classes from /src/test/... If I copy the problematic file into /src/main/... that file imports fine but error reappears with the next imported file, and so on.
Note that command clicking the 'missing' file opens its source in VSCode, so I know it's there.
import is standard:
import com.foo.bar.baz.math.TestMathModelFactory;
File exists under:
work/src/test/java/com/foo/bar/baz/math/TestMathModelFactory.java
It builds if I put it under:
work/src/main/java/com/foo/bar/baz/math/TestMathModelFactory.java
Expect it to import, but get:
RTPTest.java:3: error: cannot find symbol
import com.foo.bar.baz.math.TestMathModelFactory;
^
I know I'm doing something stupid, but ¯\_(ツ)_/¯

LOL, was my own Pebkac issue. I was trying to run the tests via the VScode "Code Runner" extension – which, in retrospect, has no idea how the project is set up. When I ran the tests via the "Java Test Runner" extension, they ran fine.
I told you the issue was my stupidity! Thanks for the ideas anyways!

Related

Not able to import Selenium jar files

Not able to import Selenium jar files in Eclipse for some reason, while importing first time from quick fixes it works showing no error after saving the program it showing me that import is not working
Below is code:
Note: The issues arise only for Java projects only
A solution would be to use maven for the dependency management. Eventhough a quick demo with just a couple of dependecies should be ok in eclipse it is sometimes a pain in the a.
Try rebuilding the project. Build -> Build Project, and check the project setup. Eclipse gives also a error log when sth goes wrong. Have you taken a look at it? Problems View.

.class file stopped getting generated suddenly in Eclipse IDE

I am working on an automation project where I automate manual processes of general insurance sector using JAVA and SELENIUM WEBDRIVER. I have created a java project in eclipse. Inside it under src I created a single package containing 6 .java files.
I wrote 90% of the code and tested all the files. They were running properly and showing the automated output. One day I appended some lines of code to a java file. It was called from main method class where main method class suddenly started showing error under the name of that class. Firstly it said to import the class which itself was in the same package of main class. Secondly even after clicking on importing command of the class the error did not went away.
Lastly I cleaned the project in eclipse and the error went away but when I tried to run the project then it gave the error as NoClassDefFoundError and ClassNotFoundException. I checked the bin folder inside the project folder on drive. There .class file for the error class was missing while other classes .class file was present. Everytime I make changes in the main method class and save it eclipse starts showing error under that class name. The error goes when I clean the project. It is a repetitive occurrence in eclipse.
Code for all java classes without main method are 99% same still error is coming for one java class only while other java classes are running fine with almost the same lines of code
Can anyone please explain me the reason behind such behaviour of java compiler in eclipse. Its really a strange show of java compiler the reason behind which I am not able to understand. Please do let me know about the reason behind this act of JAVA compiler in eclipse as I am very curious to know the reason for it. I use jdk 1.8 and selenium standalone server ver 3.0.1
Thanks in advance for your answer.

TestNG, Intellij IDEA, Command Line Test Run Error: Cannot Find Class in Classpath

So I've seen this error is rather common, however most responses relate to Eclipse. I am using Intellij IDEA and getting the same error. This error is a little different than others in that it specifies not only the java test file, but the package as well. Other errors I've seen did not mention the package in the error.
So far I have tried:
1. Set CLASSPATH=%Path to dependancy module1%;%Path to dependancy module2%;%Path to SeleniumServer jar%;%Path to code libraries%;%Path to TestNG jar%;%Path to XML file%, etc...
2. Invalidating and rebuilding cache in IDEA.
3. Verifying that the package is actually specified in the XML file.
Extra info: I am not using Maven, or I would just use that for the scheduled runs I'm going for. IDEA Community 15.0.6. TestNG 6.8.8.

Conversion to Dalvik format failed with error 1 while compiling jitsi project

I am trying to compile and run the project
https://github.com/jitsi/jitsi-android on Eclipse by Importing.
I have imported the project successfully,Added External Jar files and Fix some of compilation errors.
When I try to run app, It is giving
Conversion to Dalvik format failed with error 1 Error on the console.So that I Clean the project, checked the all the jar files from Order and Export tab and build it again.
but it doesn't work for me.
Finally, I unchecked the all the libraries from Order and Export tab,build and run it again.
But still its giving me same error and my application is getting crashed every time i run it.
Any help will be appreciated , i really want to run this application.
here is my libs folder screenshot:-
I've had the same problem once.
Here is what I found out when I was trying to solve my issue:
The error is caused when there are two Classes/Packages with the same name (For example when LibaryX has Class org.a.b.c.Sample and LibaryY has class org.a.b.c.Sample aswell)
Different approaches which worked for some people (So if you have the error yourself, make sure to test following things out):
A) Two Libaries have the exactly same package/class-> Delete the class in one of the Libaries
B) One Jar is detected twice because it's for example in the project source folder and in the Java Build Path Libaries aswell
C) Updating Proguard often fixes it aswell (Put the new Proguard jars in [Android SDK folder]\tools\proguard\lib)
D) Cleaning the Project also helped many people (you already did that, so that won't be your solution)
When I had this issue myself it was caused because I did not follow the instructions of one of the libaries that I used. After following the libary instructions step by step, everything worked fine again.
Greetings
Felix

Idea + Play Framework - cannot resolve method/symbol

I use IntelliJ IDEA 12, Play 2.2.0, I have Scala plugin installed, Play 2.0 support plugin installed.
I created java play application via termina (play new). Andas you can see in this pictures I always get this error: "cannot resolve method ok()" or "cannot resolve symbol at"
http://sluchatka.kvalitne.cz/pics/1.png
http://sluchatka.kvalitne.cz/pics/2.png
I searched the web for this problem the whole day, but I didn't find solution.
Can you please help me?
The first problem (unable to resolve reference to template) is because your template probably has not been compiled by the moment (and thus IDEA does not see compiled template and can't resolve reference to it).
I usually develop Play apps having ~run command launched in Play console. So that any changes to templates are immediately compiled and changes detected by IDEA.
As for the second one it seems like a deficiency in Play IDEA plugin. It does not work seamlessly within templates I should say. Lots of glitches. The best way I found is to have ~run launched so that small problems are detected immediately.
According to intelliJ support it is better to import the command line created play 2 project using the IDE import project wizard instead.
File -> Import Project
Select play2 project location
Import as SBT project
This was due to the "play idea" command being outdated or not fully compatible with the current play 2 and scala plugins for intelliJ.
A bonus is that errors start to appear properly, we had trouble with that earlier.
I was having a similar issue with Play 2.4.2 and Intellij 14.1.4. I could run the basic "play-java" example/starter app in Intellij, even though the editor showed errors like "cannot resolve method ok()".
Here's what solves the problem for me:
Before starting, make sure your project is not open in Intellij.
Delete the ".idea" folder from your existing app, OR just create a new app using "activator new".
On the command line, cd to the app's folder and compile using "activator compile".
In Intellij, File -> Open, and select your app's folder. For the SBT import options, I left the boxes unchecked (e.g. "Use auto-import", "Create directories for empty content roots automatically", etc.) but I don't think it matters.
Once everything finishes loading, you shouldn't see the errors any more.
This click in the Project Structure is your answer.

Categories

Resources