Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

junit Testing #837

Closed
Zirhi opened this issue Mar 14, 2019 · 12 comments
Closed

junit Testing #837

Zirhi opened this issue Mar 14, 2019 · 12 comments

Comments

@Zirhi
Copy link

Zirhi commented Mar 14, 2019

So I am writing a test file for a program.

The instruction requires me to use:
import static org.junit.Assert.*;
import org.junit.Test;

However, when I get an error: The import org.junit cannot be resolvedJava(268435846)

Please what is this issue and how do I go about resolving it.

@yaohaizh
Copy link
Collaborator

@Zirhi Could you share your sample project here?

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

Hi, do you want only the test file? I am not allowed to share the project on public sites as it is a school assignment

@yaohaizh
Copy link
Collaborator

@Zirhi Do you have add the junit as the project dependency?

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

The assignment doesn't specify, but if it helps I think I can do that.

@yaohaizh
Copy link
Collaborator

#501

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

So I tried the procedure from the provide gif in #501

I created a lib folder and used the command user$ cp ../lib/*.jar lib/

Returned
cp: ../lib/*.jar: No such file or directory

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

or is that not what solves my problem

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

Issue has been resolved

@fbricon
Copy link
Collaborator

fbricon commented Mar 14, 2019

So what solved it?

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

I downloaded these two files from junit.org/junit4/

https://github.com/junit-team/junit4/wiki/Download-and-Install

Seems to get rid of the resolving error

@Zirhi
Copy link
Author

Zirhi commented Mar 14, 2019

So I do not get the red line error on my import statements anymore, but on compiling the program I still get this error:

TestOne.java:1: error: package org.junit does not exist
import static org.junit.Assert.*;

@fbricon
Copy link
Collaborator

fbricon commented Mar 14, 2019

compiling as in calling javac from a terminal? If that's the case, you need to add the jars to the classpath.

 javac –classpath C:\path\to\junit.jar;C:\path\to\hamcrest-core.jar TestOne.Java

and, to run the class:

 java –classpath C:\path\to\junit.jar;C:\path\to\hamcrest-core.jar TestOne

if you're on Mac or Linux, the path separator is :.

If you google about how to set the Java classpath, you'll find alternative ways of doing it like in https://howtodoinjava.com/java/basics/java-classpath/

Now in vscode-java, all that is not necessary, as compilation happens under the hood, and if you installed the Java Debugger extension and/or the Java Test runner, you'll be able to run your code directly from within VS Code, by clicking on "code lenses".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants