diff --git a/build.gradle b/build.gradle index 7d7b75c3..bef88aa8 100644 --- a/build.gradle +++ b/build.gradle @@ -141,6 +141,7 @@ dependencies { testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:5.14.2' testImplementation 'com.google.truth:truth:1.4.4' + testImplementation 'com.team2813:testing' implementation 'com.team2813:lib2813' implementation 'com.team2813:limelight' @@ -154,7 +155,9 @@ test { // Simulation configuration (e.g. environment variables). wpi.sim.addGui().defaultEnabled = true wpi.sim.addDriverstation() + downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':lib:jar') +downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':testing:jar') downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':limelight:jar') // Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') diff --git a/settings.gradle b/settings.gradle index dfd42db5..e3ab5fd5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -33,5 +33,6 @@ includeBuild('lib2813') { dependencySubstitution { substitute module('com.team2813:lib2813') using project(':lib') substitute module('com.team2813:limelight') using project(':limelight') + substitute module('com.team2813:testing') using project(':testing') } } \ No newline at end of file diff --git a/src/test/java/com/team2813/CommandTester.java b/src/test/java/com/team2813/CommandTester.java deleted file mode 100644 index f8ccf7cc..00000000 --- a/src/test/java/com/team2813/CommandTester.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.team2813; - -import edu.wpi.first.wpilibj2.command.Command; - -/** - * Allows tests to run commands. - * - *
Tests can get an instance by using {@link CommandTesterExtension}. - */ -public interface CommandTester { - - /** Schedules the provided command and runs it until it completes. */ - void runUntilComplete(Command command); -} diff --git a/src/test/java/com/team2813/CommandTesterExtension.java b/src/test/java/com/team2813/CommandTesterExtension.java deleted file mode 100644 index 6bddc51f..00000000 --- a/src/test/java/com/team2813/CommandTesterExtension.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.team2813; - -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.simulation.DriverStationSim; -import edu.wpi.first.wpilibj2.command.CommandScheduler; -import org.junit.jupiter.api.extension.AfterAllCallback; -import org.junit.jupiter.api.extension.AfterEachCallback; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.Extension; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; -import org.junit.jupiter.api.extension.ParameterResolver; - -/** - * JUnit Jupiter extension for allowing a test to schedule commands. - * - *
Example use: - * - *
{@code
- * @ExtendWith(CommandTesterExtension.class)
- * public final class FlightSubsystemTest {
- *
- * @Test
- * public void takesFlight(CommandTester commandTester) {}
- * var flight = new FlightSubsystem();
- * Command takeOff = flight.createTakeOffCommandCommand();
- * assertThat(flight.inAir()).isFalse();
- *
- * commandTester.runUntilComplete(takeOff);
- *
- * assertThat(flight.inAir()).isTrue();
- * }
- * }
- * }
- */
-public final class CommandTesterExtension
- implements Extension,
- AfterAllCallback,
- AfterEachCallback,
- BeforeAllCallback,
- ParameterResolver {
-
- @Override
- public void beforeAll(ExtensionContext context) {
- // See https://www.chiefdelphi.com/t/driverstation-getalliance-in-gradle-test/
- HAL.initialize(500, 0);
- DriverStationSim.setEnabled(true);
- DriverStationSim.notifyNewData();
- CommandScheduler.getInstance().enable();
- CommandScheduler.getInstance().unregisterAllSubsystems();
- }
-
- @Override
- public void afterEach(ExtensionContext context) {
- CommandScheduler.getInstance().unregisterAllSubsystems();
- }
-
- @Override
- public void afterAll(ExtensionContext context) {
- CommandScheduler.getInstance().unregisterAllSubsystems();
- CommandScheduler.getInstance().disable();
- DriverStationSim.setEnabled(false);
- DriverStationSim.notifyNewData();
- }
-
- @Override
- public boolean supportsParameter(
- ParameterContext parameterContext, ExtensionContext extensionContext)
- throws ParameterResolutionException {
- return CommandTester.class.equals(parameterContext.getParameter().getType());
- }
-
- @Override
- public CommandTester resolveParameter(
- ParameterContext parameterContext, ExtensionContext extensionContext) {
- return command -> {
- CommandScheduler scheduler = CommandScheduler.getInstance();
- command.schedule();
- do {
- scheduler.run();
- } while (scheduler.isScheduled(command));
- };
- }
-}
diff --git a/src/test/java/com/team2813/subsystems/IntakeTest.java b/src/test/java/com/team2813/subsystems/IntakeTest.java
index 91fc14c7..afbd33a8 100644
--- a/src/test/java/com/team2813/subsystems/IntakeTest.java
+++ b/src/test/java/com/team2813/subsystems/IntakeTest.java
@@ -6,9 +6,9 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
-import com.team2813.CommandTester;
-import com.team2813.CommandTesterExtension;
import com.team2813.IsolatedNetworkTablesExtension;
+import com.team2813.lib2813.testing.junit.jupiter.CommandTester;
+import com.team2813.lib2813.testing.junit.jupiter.WPILibExtension;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj2.command.Command;
@@ -16,7 +16,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
-@ExtendWith({IsolatedNetworkTablesExtension.class, CommandTesterExtension.class})
+@ExtendWith({IsolatedNetworkTablesExtension.class, WPILibExtension.class})
public final class IntakeTest {
final FakePIDMotor fakeMotor = mock(FakePIDMotor.class, Answers.CALLS_REAL_METHODS);
final DigitalInput mockBeamBreak = mock(DigitalInput.class);
diff --git a/src/test/java/com/team2813/subsystems/ParameterizedIntakeSubsystemTest.java b/src/test/java/com/team2813/subsystems/ParameterizedIntakeSubsystemTest.java
index 7b8c9fcd..4abd9803 100644
--- a/src/test/java/com/team2813/subsystems/ParameterizedIntakeSubsystemTest.java
+++ b/src/test/java/com/team2813/subsystems/ParameterizedIntakeSubsystemTest.java
@@ -4,10 +4,10 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
-import com.team2813.CommandTester;
-import com.team2813.CommandTesterExtension;
import com.team2813.lib2813.control.ControlMode;
import com.team2813.lib2813.control.PIDMotor;
+import com.team2813.lib2813.testing.junit.jupiter.CommandTester;
+import com.team2813.lib2813.testing.junit.jupiter.WPILibExtension;
import edu.wpi.first.wpilibj2.command.Command;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -17,7 +17,7 @@
@ParameterizedClass
@EnumSource(ControlMode.class)
-@ExtendWith(CommandTesterExtension.class)
+@ExtendWith(WPILibExtension.class)
public final class ParameterizedIntakeSubsystemTest {
private static class ConcreteParameterizedIntakeSubsystem extends ParameterizedIntakeSubsystem {