wake-up-neo.com

Keine Tests für gegeben enthalten enthält Fehler, wenn Parameterized Unit Test in Android Studio) ausgeführt wird

Ich habe versucht, den parametrisierten Komponententest wie folgt in Android Studio) auszuführen.

import Android.test.suitebuilder.annotation.SmallTest;  

import junit.framework.TestCase;    

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;  

import Java.util.Arrays;
import Java.util.Collection;    

@RunWith(Parameterized.class)
@SmallTest
public class FibonacciTest extends TestCase {
    @Parameters
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][] {
                {0, 0}, {1, 1}, {2, 1}, {3, 2}, {4, 3}, {5, 5}, {6, 8}
        });
    }   

    @Parameter // first data value (0) is default
    public /* NOT private */ int fInput;    

    @Parameter(value = 1)
    public /* NOT private */ int fExpected; 

    @Test
    public void test() {
        assertEquals(fExpected, Fibonacci.calculate(fInput));
    }
}

Das Ergebnis ist ein Fehler, der besagt, dass kein Testlauf durchgeführt wurde. Wenn ich jedoch die Parameter entfernt habe und sie in einen Einzeltest ändere. Es klappt. Jeder könnte etwas Licht ins Dunkel bringen, warum funktioniert das nicht? Wird der parametrisierte Komponententest in Android Entwicklung noch nicht unterstützt? Danke!) Unterstützt!

Unten ist der Fehler mit der Stapelverfolgung.

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:testDebug'.
> No tests found for given includes: [com.example.......FibonacciTest]
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:testDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.Java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.Java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.Java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.Java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.Java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.Java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.Java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.Java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.Java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.Java:310)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.Java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.Java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.Java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.Java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.Java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.Java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.Java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.Java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.Java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.Java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.Java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.Java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.Java:90)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.Java:54)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.Java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.Java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.Java:28)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.Java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.Java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.Java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.Java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.Java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.Java:72)
    at org.gradle.util.Swapper.swap(Swapper.Java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.Java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.Java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.Java:66)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.Java:71)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.Java:41)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.Java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.Java:246)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.Java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.Java:40)
Caused by: org.gradle.api.GradleException: No tests found for given includes: [com.example........FibonacciTest]
    at org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter.afterSuite(NoMatchingTestsReporter.Java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.Java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.Java:24)
    at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.Java:87)
    at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.Java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.Java:93)
    at com.Sun.proxy.$Proxy46.afterSuite(Unknown Source)
    at org.gradle.api.internal.tasks.testing.results.TestListenerAdapter.completed(TestListenerAdapter.Java:48)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.Java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.Java:24)
    at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.Java:87)
    at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.Java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.Java:93)
    at com.Sun.proxy.$Proxy45.completed(Unknown Source)
    at org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor.completed(StateTrackingTestResultProcessor.Java:69)
    at org.gradle.api.internal.tasks.testing.results.AttachParentTestResultProcessor.completed(AttachParentTestResultProcessor.Java:52)
    at org.gradle.api.internal.tasks.testing.processors.TestMainAction.run(TestMainAction.Java:51)
    at org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter.execute(DefaultTestExecuter.Java:75)
    at org.gradle.api.tasks.testing.Test.executeTests(Test.Java:527)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.Java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.Java:226)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.Java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.Java:208)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.Java:589)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.Java:572)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.Java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.Java:61)
    ... 57 more
BUILD FAILED
Total time: 4.153 secs
No tests found for given includes: [com.example......FibonacciTest]
38
Elye

Es wurde eine Möglichkeit gefunden, den Test in Android Studio) auszuführen. Anscheinend führt das Ausführen mit Gradle Configuration keinen Test aus. Stattdessen verwende ich die JUnit-Konfiguration. Die einfache Möglichkeit hierfür ist die Auswahl Ihres Tests Auszuführende Klasse und Rechtsklick. Wählen Sie dann Ausführen. Danach werden zwei Ausführungsoptionen angezeigt. Wählen Sie die untere (JUnit) gemäß dem Bild ausenter image description here

(Hinweis: Wenn Sie keine 2-Run-Konfiguration zur Auswahl finden, müssen Sie zuerst Ihre zuvor verwendete Konfiguration (Gradle-Konfiguration) entfernen. Klicken Sie dazu oben auf das Symbol "Run/Debug-Konfiguration auswählen" Symbolleiste.

12
Elye

Fügen Sie Ihrem build.gradle hinzu:

test {
    useJUnitPlatform()
}
59
Przemek315

Stellen Sie sicher, dass Sie die Annotation @Test Aus der richtigen Bibliothek importieren:

import org.junit.jupiter.api.Test

nicht

import org.junit.Test

37
LostAtSea

Um zu der bereits großartigen und einfachen Lösung von Przemek315 hinzuzufügen, die gleiche Konfiguration, wenn Sie Kotlin DSL verwenden:

tasks.test {
    useJUnitPlatform()
}
15
skryvets

Ich verwende JUnit 4 und habe bei mir die IntelliJ-Einstellungen für 'Gradle -> Tests ausführen mit' von 'Gradle (Standard)' in 'IntelliJ IDEA' geändert.

(enter image description here

Quelle meines Fixes: https://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/

13
trishke