Средство запуска консоли JUnit 5 не находит мой тест, когда указан файлJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Средство запуска консоли JUnit 5 не находит мой тест, когда указан файл

Сообщение Anonymous »

Я пытаюсь настроить JUnit5 (версия 1.10.3) для запуска указанного мною тестового файла. в настоящее время мой файл LocalLibTests.java (тестовый файл) выглядит так

Код: Выделить всё

import example.util.Calculator;
import org.junit.jupiter.api;

public final Calculator calculator = new Calculator();

@DisplayName("Single test successful")
@Test
void addition() {
assertEquals(2, calculator.add(1, 1));
}
но использую ли я Discover

Код: Выделить всё

java -jar junit-platform-console-standalone.jar discover --select-file="C:\_Work\_git\script-library\java\testApp\lib\LocalLibTests.java"
.

Код: Выделить всё

C:\_Work\_git\script-library\java\_Testing>java -jar junit-platform-console-standalone.jar discover --select-file="C:\_Work\_git\script-library\java\testApp\lib\LocalLibTests.java"

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

.
+-- JUnit Jupiter
+-- JUnit Vintage
'-- JUnit Platform Suite

[         3 containers found ]
[         0 tests found      ]
или выполнить

Код: Выделить всё

java -jar junit-platform-console-standalone.jar execute --select-file=C:\_Work\_git\script-library\java\testApp\lib\LocalLibTests.java
.

Код: Выделить всё

C:\_Work\_git\script-library\java\_Testing>java -jar junit-platform-console-standalone.jar execute --select-file=C:\_Work\_git\script-library\java\testApp\lib\LocalLibTests.java

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

.
+-- JUnit Jupiter [OK]
+-- JUnit Vintage [OK]
'-- JUnit Platform Suite [OK]

Test run finished after 37 ms
[         3 containers found      ]
[         0 containers skipped    ]
[         3 containers started    ]
[         0 containers aborted    ]
[         3 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]
он ​​не находит тест
и путь к файлу ведет к файлу

Код: Выделить всё

C:\_Work\_git\script-library\java\testApp\lib>dir
Volume in drive C is Windows
Volume Serial Number is 3E3A-0ADC

Directory of C:\_Work\_git\script-library\java\testApp\lib

01/08/2024  02:36 PM              .
16/07/2024  02:32 PM              ..
05/08/2024  11:19 AM               112 LocalLib.java
05/08/2024  11:45 AM               235 LocalLibTests.java
2 File(s)            347 bytes
2 Dir(s)  120,354,050,048 bytes free
Я начал с примера из Руководства пользователя JUnit 5 и использовал его, делал то же самое, поэтому начинаю думать, что в командной строке я ошибаюсь

Код: Выделить всё

import static org.junit.jupiter.api.Assertions.assertEquals;

import example.util.Calculator;

import org.junit.jupiter.api.Test;

class MyFirstJUnitJupiterTests {

private final Calculator calculator = new Calculator();

@Test
void addition() {
assertEquals(2, calculator.add(1, 1));
}

}
Я также использовал --select-class и --classpath, как было предложено, и хотя он выдает ошибку о том, что не может найти файлы, он делает нет смысла, поскольку путь и имя класса будут правильными при использовании примера из Руководства пользователя JUnit 5

Код: Выделить всё

java -jar junit-platform-console-standalone.jar execute --classpath="C:\_Work\_git\script-library\java\testApp\lib" --select-class="MyFirstJUnitJupiterTests"
.

Код: Выделить всё

C:\_Work\_git\script-library\java\_Testing>java -jar junit-platform-console-standalone.jar execute --classpath="C:\_Work\_git\script-library\java\testApp\lib"  --select-class="MyFirstJUnitJupiterTests"

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:132)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:78)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:99)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
at org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:47)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:63)
at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:102)
at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$1(ConsoleTestExecutor.java:71)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.replaceThreadContextClassLoaderAndInvoke(CustomContextClassLoaderExecutor.java:42)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:71)
at org.junit.platform.console.options.ExecuteTestsCommand.execute(ExecuteTestsCommand.java:61)
at org.junit.platform.console.options.ExecuteTestsCommand.execute(ExecuteTestsCommand.java:27)
at org.junit.platform.console.options.BaseCommand.call(BaseCommand.java:74)
at org.junit.platform.console.shadow.picocli.CommandLine.executeUserObject(CommandLine.java:2041)
at org.junit.platform.console.shadow.picocli.CommandLine.access$1500(CommandLine.java:148)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at org.junit.platform.console.shadow.picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at org.junit.platform.console.shadow.picocli.CommandLine.execute(CommandLine.java:2170)
at org.junit.platform.console.options.MainCommand.runCommand(MainCommand.java:137)
at org.junit.platform.console.options.MainCommand.run(MainCommand.java:125)
at org.junit.platform.console.options.CommandFacade.run(CommandFacade.java:36)
at org.junit.platform.console.ConsoleLauncher.run(ConsoleLauncher.java:57)
at org.junit.platform.console.ConsoleLauncher.run(ConsoleLauncher.java:42)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:35)
Caused by: org.junit.platform.commons.JUnitException: ClassSelector [className = 'MyFirstJUnitJupiterTests', classLoader = null] resolution failed
at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:103)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:83)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:46)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
...  29 more
Caused by: org.junit.platform.commons.PreconditionViolationException: Could not load class with name: MyFirstJUnitJupiterTests
at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:95)
at org.junit.platform.commons.function.Try$Failure.getOrThrow(Try.java:335)
at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:94)
at org.junit.jupiter.engine.discovery.ClassSelectorResolver.resolve(ClassSelectorResolver.java:66)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:135)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1686)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:144)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:574)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:662)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:189)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:126)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:92)
... 34 more
Caused by: java.lang.ClassNotFoundException: MyFirstJUnitJupiterTests
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
at java.base/java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:870)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:529)
at java.base/java.lang.Class.forName(Class.java:508)
at org.junit.platform.commons.util.ReflectionUtils.lambda$tryToLoadClass$9(ReflectionUtils.java:832)
at org.junit.platform.commons.function.Try.lambda$call$0(Try.java:57)
at org.junit.platform.commons.function.Try.of(Try.java:93)
at org.junit.platform.commons.function.Try.call(Try.java:57)
at org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(ReflectionUtils.java:795)
at org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(ReflectionUtils.java:751)
at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:92)
... 48 more

Usage: junit execute [OPTIONS]
(остальное — это типичная документация по комментариям)

Подробнее здесь: https://stackoverflow.com/questions/788 ... -specified
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»