From 2e8b5b54707b0a70d0e2a95cb58e37331f0f1dee Mon Sep 17 00:00:00 2001 From: "Keenan D. Buckley" Date: Sat, 11 Apr 2020 12:43:42 -0600 Subject: [PATCH] Add Subsystem Test Template --- .templates/SubsystemTest.java | 65 +++++++++++++++++++ .../robot/subsystems/LEDSubsystemTest.java | 36 ++++++++-- 2 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 .templates/SubsystemTest.java diff --git a/.templates/SubsystemTest.java b/.templates/SubsystemTest.java new file mode 100644 index 0000000..a138c61 --- /dev/null +++ b/.templates/SubsystemTest.java @@ -0,0 +1,65 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.utility; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import org.junit.*; + +import edu.wpi.first.wpilibj.*; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +/** + * Add your docs here. + */ +public class UtilityTest { + @Test + public void testConstructor() { + // Arrange + Spark ledController = mock(Spark.class); + + // Act + LED led = new LED(ledController); + + // Assert + assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001); + } + + @Test + public void testPatterns() { + // Arrange + Spark ledController = mock(Spark.class); + LED led = new LED(ledController); + + // Act + led.setPattern(LEDPatterns.RAINBOW_RAINBOW); + + // Assert + assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001); + + // Act + led.setPattern(LEDPatterns.BLUE_BREATH); + + // Assert + assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001); + + // Act + led.setPattern(LEDPatterns.SOLID_BLACK); + + // Assert + assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001); + } + + private void wait(int millis) { + try { + Thread.sleep(millis); + } catch (Exception e) {} + } +} diff --git a/src/test/java/frc4388/robot/subsystems/LEDSubsystemTest.java b/src/test/java/frc4388/robot/subsystems/LEDSubsystemTest.java index 3852edb..b1dd630 100644 --- a/src/test/java/frc4388/robot/subsystems/LEDSubsystemTest.java +++ b/src/test/java/frc4388/robot/subsystems/LEDSubsystemTest.java @@ -18,24 +18,46 @@ import frc4388.utility.LEDPatterns; * Add your docs here. */ public class LEDSubsystemTest { - Spark ledController = mock(Spark.class); - LED led = new LED(ledController); + @Test + public void testConstructor() { + // Arrange + Spark ledController = mock(Spark.class); + + // Act + LED led = new LED(ledController); + + // Assert + assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001); + } @Test public void testPatterns() { - // TEST 1 - assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001); + // Arrange + Spark ledController = mock(Spark.class); + LED led = new LED(ledController); - // TEST 2 + // Act led.setPattern(LEDPatterns.RAINBOW_RAINBOW); + + // Assert assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001); - // TEST 3 + // Act led.setPattern(LEDPatterns.BLUE_BREATH); + + // Assert assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001); - // TEST 4 + // Act led.setPattern(LEDPatterns.SOLID_BLACK); + + // Assert assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001); } + + private void wait(int millis) { + try { + Thread.sleep(millis); + } catch (Exception e) {} + } }