Я пытаюсь запустить Tests Junit Tests в коде Visual Studio без использования Maven или Gradle , просто используя простые. Java Files и .jar . .vscode/funs.json :
{
"java.project.sourcePaths": [
"src/main/java",
"src/test/java"
],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
Inside the lib/ folder, I placed:
junit-4.13.2.jar
hamcrest-core-1.3.jarTestHello/
├── lib/
│ ├── junit-4.13.2.jar
│ └── hamcrest-core-1.3.jar
├── src/
│ ├── main/java/ExceptionTest/MessageUtil.java
│ └── test/java/ExceptionTest/TestJunit.java
├── .vscode/settings.json
What worked initially:
The first time I wrote my test, I just:
Created .java files manually in a folder,
Clicked on the Testing tab in the left sidebar,
VS Code asked me to enable "Java Testing", and I accepted.
It worked! I saw the green triangle "Run Test" icons next to my test methods.
The problem:
After closing and reopening VS Code later, now:
When I click on the Testing panel, it says: "No tests found"
The test annotations like @Test, @Before, and Assert are underlined with errors:
The import org.junit cannot be resolved
Test cannot be resolved to a type
Assert cannot be resolved
The green triangle icons (Run Test) have disappeared from the gutter
My test class (TestJunit.java):
package ExceptionTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
String message = "Robert";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testSalutationMessage() {
message = "Hi!" + "Robert";
assertEquals(message, messageUtil.salutationMessage());
}
}
Question:
How can I make VS Code persistently recognize and run JUnit tests without Maven or Gradle? Why did the tests disappear after restarting VS Code? Is there a way to force VS Code to re-scan and show the test icons again?
Подробнее здесь: https://stackoverflow.com/questions/795 ... een-triang