mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-21 14:42:27 +00:00
Tests
- Get testing working through maven: configure junit and surefire versions and block resolution of conflicting surefire version through com.github.psambit9791 - Fix PamZip test (zip file was missing due to .gitignore). This is now the same file as blue_whale_24.kgu (but renamed to .zip) - Fixed scaffolding of ExportTest (still doesn't test anything but at it's not longer crashing) - Force tests to run in separate VMs to reduce the impact of the PamController singleton Signed-off-by: Merlijn van Deen <m.vandeen@fugro.com>
This commit is contained in:
parent
e7cd4fa317
commit
6ac5877cdd
1
.gitignore
vendored
1
.gitignore
vendored
@ -19,6 +19,7 @@
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
!src/test/**/*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
*.dll
|
||||
|
35
pom.xml
35
pom.xml
@ -182,7 +182,15 @@
|
||||
-->
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<reuseForks>false</reuseForks>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- Plugin which creates a .dmg file for MacOS.
|
||||
<plugin>
|
||||
@ -228,7 +236,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin> -->
|
||||
|
||||
</plugins>
|
||||
|
||||
|
||||
@ -334,6 +341,17 @@
|
||||
|
||||
|
||||
<!-- ************************* Dependencies ************************************* -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>5.11.3</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
<!--jpam project - utilities -->
|
||||
@ -341,6 +359,13 @@
|
||||
<groupId>io.github.macster110</groupId>
|
||||
<artifactId>jpamutils</artifactId>
|
||||
<version>0.0.59d</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<!-- com.github.psambit9791:wavfile:jar:0.1 pulls in various junit dependencies which breaks our own testing -->
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--jpam project - Deep learning java library -->
|
||||
@ -1039,5 +1064,11 @@
|
||||
|
||||
|
||||
|
||||
<!-- Test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,4 +0,0 @@
|
||||
package PamController.test;
|
||||
|
||||
public class PamControllerTestHelper {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class OneBandControlTest {
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package test.export;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
import test.helper.PamControllerTestHelper;
|
||||
import clickDetector.ClickControl;
|
||||
import clickDetector.ClickDetector;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import clickDetector.ClickDetection;
|
||||
@ -18,14 +18,16 @@ public class ExportTest {
|
||||
* Test exporting detections to mat files.
|
||||
*/
|
||||
@Test
|
||||
public void matFileTest() {
|
||||
|
||||
public void matFileTest() throws Exception {
|
||||
PamControllerTestHelper.InitializePamControllerForTesting();
|
||||
|
||||
System.out.println("Matched template classifier test: match corr");
|
||||
|
||||
//create a list of click detections.
|
||||
ClickDetection clickDetection = new ClickDetection(0, 0, 0, null, null, 0);
|
||||
|
||||
|
||||
|
||||
//create a list of click detections.
|
||||
ClickControl control = new ClickControl("name");
|
||||
ClickDetector detector = new ClickDetector(control);
|
||||
ClickDetection clickDetection = new ClickDetection(0, 0, 0, detector, null, 0);
|
||||
|
||||
//now open the mat file and check that we have all the data from these click detections.
|
||||
|
||||
}
|
||||
|
29
src/test/helper/PamControllerTestHelper.java
Normal file
29
src/test/helper/PamControllerTestHelper.java
Normal file
@ -0,0 +1,29 @@
|
||||
package test.helper;
|
||||
|
||||
import PamController.PamController;
|
||||
import PamController.PamSettingManager;
|
||||
import pamguard.GlobalArguments;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Helper to initialize a headless {@link PamController} from unit tests.
|
||||
* This will only initialize the {@link PamController} once; tests are responsible for cleaning
|
||||
* up any changes they make to the configuration.
|
||||
*/
|
||||
public class PamControllerTestHelper {
|
||||
private static boolean isInitialized = false;
|
||||
|
||||
public static void InitializePamControllerForTesting() throws IOException {
|
||||
if (!isInitialized) {
|
||||
isInitialized = true;
|
||||
File file = File.createTempFile("OneBandControlTest", "psfx");
|
||||
file.deleteOnExit();
|
||||
|
||||
GlobalArguments.setParam(GlobalArguments.BATCHFLAG, "true");
|
||||
PamSettingManager.remote_psf = file.getAbsolutePath();
|
||||
PamController.create(PamController.RUN_NOTHING);
|
||||
}
|
||||
}
|
||||
}
|
41
src/test/noiseOneBand/OneBandControlTest.java
Normal file
41
src/test/noiseOneBand/OneBandControlTest.java
Normal file
@ -0,0 +1,41 @@
|
||||
package test.noiseOneBand;
|
||||
|
||||
import PamController.PamController;
|
||||
import PamController.soundMedium.GlobalMedium;
|
||||
import test.helper.PamControllerTestHelper;
|
||||
import noiseOneBand.OneBandControl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class OneBandControlTest {
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
PamControllerTestHelper.InitializePamControllerForTesting();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void MeasurementnameTest() {
|
||||
try {
|
||||
assertEquals(4, OneBandControl.NMEASURES);
|
||||
assertThrows(Exception.class, () -> OneBandControl.getMeasurementName(4));
|
||||
|
||||
PamController.getInstance().getGlobalMediumManager().setCurrentMedium(GlobalMedium.SoundMedium.Water, false);
|
||||
assertEquals("RMS (dB re 1\u00B5Pa)", OneBandControl.getMeasurementName(0));
|
||||
assertEquals("0-Peak (dB re 1\u00B5Pa)", OneBandControl.getMeasurementName(1));
|
||||
assertEquals("Peak-Peak (dB re 1\u00B5Pa)", OneBandControl.getMeasurementName(2));
|
||||
assertEquals("Integrated SEL (dB re 1\u00B5Pa\u00B2s)", OneBandControl.getMeasurementName(3));
|
||||
|
||||
PamController.getInstance().getGlobalMediumManager().setCurrentMedium(GlobalMedium.SoundMedium.Air, false);
|
||||
assertEquals("RMS (dB re 20\u00B5Pa)", OneBandControl.getMeasurementName(0));
|
||||
assertEquals("0-Peak (dB re 20\u00B5Pa)", OneBandControl.getMeasurementName(1));
|
||||
assertEquals("Peak-Peak (dB re 20\u00B5Pa)", OneBandControl.getMeasurementName(2));
|
||||
assertEquals("Integrated SEL (dB re 400\u00B5Pa\u00B2s)", OneBandControl.getMeasurementName(3));
|
||||
} finally {
|
||||
PamController.getInstance().getGlobalMediumManager().setCurrentMedium(GlobalMedium.SoundMedium.Water, false);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user