microsoft / vscode-java-test

Run and debug Java test cases in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test
Other
295 stars 127 forks source link

Class Not Found Exception #1695

Closed Daniil-Ivanov1 closed 4 months ago

Daniil-Ivanov1 commented 4 months ago

Hello everyone When trying to run SpringBootTest, it crashes with an error that it cannot find the @Autowired fields, although everything works in IDEA . The project structure looks like this:

public interface TestData {

void setUser(); void setScenario();

}

@SpringBootTest(classes = {AbstractTestConfiguration.BaseConfiguration.class}) @Slf4j @EmbeddedKafka public abstract class AbstractTestConfiguration implements TestData {

@BeforeAll public static void startPostgres() { ... }

@Autowired protected SomeField someFIeld;

@Autowired private SomeJpaRespository someJpaRepostitory;

@Test public void testContextStarted() { ... }

}

public class SomeTestClass extends AbstractTestConfigiuration {

implements setters from interface

}

NoClassDefFoundError: SomeJpaRespositore

Using: Mac OS Sonome 14.4.1 Temurin JDK 17 Red Hat Language Support v1.31.0 Test Runner For Java v0.41.1 maven 3.9.5

jdneo commented 4 months ago

Could you share a sample project for this issue?

Daniil-Ivanov1 commented 4 months ago

@jdneo This code belongs to my company. I can implement the approximate logic and send it to you

Daniil-Ivanov1 commented 4 months ago

@jdneo Example here: https://github.com/Daniil-Ivanov1/ClassNotFoundException

image image
jdneo commented 4 months ago

I run mvn clean test at the root, but failed

image

Is the packaging type of the module model meant to be pom?

Daniil-Ivanov1 commented 4 months ago

@jdneo Hi! I found a legitimate problem! In our project in pom.xml dependencies have a "classifier" set Which is why the test does not find classes

jdneo commented 4 months ago

I see. classifier is not well supported now.

See: https://github.com/microsoft/vscode-java-test/issues/775 & https://github.com/redhat-developer/vscode-java/issues/1031

Daniil-Ivanov1 commented 4 months ago

@jdneo Hi! I found a workaround. I think it's worth publishing this. It is necessary to duplicate dependencies. If one has the classifier tag, then add the same dependency next to it without the tag