Setting up Junit-jupiter-5.8.1 in my java project

54 views Asked by At

I can't get a Junit dependency to clear in vscode.

here's my test class

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class APITest {
    @Test
    public void testGetJsonString() {
        APIcaller APIcaller = new APIcaller();
        
        try {
            String jsonString = APIcaller.getJsonString(12345);
            
            // Assert that the returned jsonString is not null
            Assertions.assertNotNull(jsonString);
            
     
            
        } catch (Exception e) {
            // Handle any exceptions that occur during the test
            Assertions.fail("An exception occurred: " + e.getMessage());
        }
    }
}

here is my .classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="lib" path="lib/junit-jupiter-5.8.1.jar"/>
    <classpathentry kind="lib" path="lib/json-simple-1.1.1.jar"/>
</classpath>

For context I'm making a small java program that manipulates some data I get from a graphQL query. I'm working in vsc and nvim on Ubuntu I have java test runner and java debugging extentions installed

I downloaded the the jar with curl and put it in the lib folder. I also made a .classpath I'd heard that might help but others said it's only for dependency managers like Maven & Gradle.

1

There are 1 answers

0
JialeDu On

If your project is not managed with maven or gradle, add the jar dependencies directly in JAVA PROJECTS by clicking the plus sign.

https://code.visualstudio.com/docs/java/java-project#_manage-dependencies-for-unmanaged-folder

enter image description here

If you are using a build tool, add it according to how the build tool is managed, such as pom.xml in maven. You can also learn more about it in the official documentation

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html