Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Add automated tests #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
target
.idea
22 changes: 22 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
stages:
- build
- test

build-package:
stage: build
tags:
- matlab-R2017b
script:
- mvn install
artifacts:
paths:
- target/*.zip
- target/*.tar.gz

test-package:
stage: test
tags:
- matlab-R2017b
script:
- PATH=/usr/local/MATLAB/R2017b/bin:$PATH
- mvn -P test-matlab
56 changes: 40 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

<groupId>ome</groupId>
<artifactId>bio-formats-matlab</artifactId>
<version>5.8.1-SNAPSHOT</version>
<version>5.8.2</version>
<packaging>pom</packaging>

<name>Bio-Formats bundle collection</name>
<description>Create matlab of Bio-Formats jars and tools for distribution.</description>
<name>Bio-Formats matlab package</name>
<description>Create matlab package of Bio-Formats jars and tools for distribution.</description>
<url>https://www.openmicroscopy.org/bio-formats</url>
<inceptionYear>2005</inceptionYear>

Expand All @@ -23,10 +23,13 @@
When possible, we advise using the relevant groupId and version
properties for your dependencies rather than hardcoding them. -->

<test.output.dir>${basedir}/target/matlab-test-results</test.output.dir>
<test.output>${test.output.dir}/report.xml</test.output>

<date>${maven.build.timestamp}</date>
<year>2018</year>
<project.rootdir>${basedir}</project.rootdir>
<bioformats.version>5.8.1-SNAPSHOT</bioformats.version>
<bioformats.version>5.8.2</bioformats.version>
<bio-formats_package.version>${bioformats.version}</bio-formats_package.version>
<imagej1.version>1.48s</imagej1.version>
<log4j.version>1.2.17</log4j.version>
Expand All @@ -51,7 +54,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand All @@ -70,12 +73,7 @@
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>

<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
</plugin>

<plugin>
Expand All @@ -90,7 +88,7 @@

<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
</plugin>

<plugin>
Expand All @@ -107,7 +105,12 @@

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
</plugin>

<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>

<plugin>
Expand Down Expand Up @@ -136,6 +139,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack-ome-xml</id>
Expand Down Expand Up @@ -289,7 +293,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack</id>
Expand All @@ -312,6 +316,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>create-test-output-dir</id>
<phase>test</phase>
<configuration>
<tasks>
<delete dir="${test.output.dir}"/>
<mkdir dir="${test.output.dir}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand All @@ -329,13 +353,13 @@
<executable>matlab</executable>
<workingDirectory>${java.io.tmpdir}</workingDirectory>
<environmentVariables>
<MATLABPATH>${project.build.directory}/test-matlab/bio-formats-matlab-${project.version}</MATLABPATH>
<MATLABPATH>${project.build.directory}/test-matlab/bio-formats-matlab-${project.version}${path.separator}${basedir}/test</MATLABPATH>
</environmentVariables>
<arguments>
<argument>-nodesktop</argument>
<argument>-nosplash</argument>
<argument>-r</argument>
<argument>runtests ${project.rootdir}/test</argument>
<argument>runbfxunit ${test.output}</argument>
</arguments>
</configuration>
</plugin>
Expand Down
20 changes: 8 additions & 12 deletions test/ReaderTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

classdef ReaderTest < TestBfMatlab

properties
reader
sizeX
Expand All @@ -35,14 +35,9 @@
sizeC
sizeT
end

methods
function self = ReaderTest(name)
self = self@TestBfMatlab(name);
end

function setUp(self)
setUp@TestBfMatlab(self)

methods (TestMethodSetup)
function ReaderTestSetUp(self)
javaaddpath(self.jarPath);
self.reader = loci.formats.in.FakeReader();
self.sizeX = self.reader.DEFAULT_SIZE_X;
Expand All @@ -53,13 +48,14 @@ function setUp(self)
loci.common.DebugTools.setRootLevel('ERROR');
import ome.units.UNITS.*;
end

function tearDown(self)
end

methods (TestMethodTeardown)
function ReaderTestTearDown(self)
if ~isempty(self.reader),
self.reader.close();
self.reader = [];
end
tearDown@TestBfMatlab(self)
end
end
end
22 changes: 10 additions & 12 deletions test/TestBfCheckJavaMemory.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,46 @@
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

classdef TestBfCheckJavaMemory < TestBfMatlab

properties
minMemory
warning_id = ''
end

methods
function self = TestBfCheckJavaMemory(name)
self = self@TestBfMatlab(name);
end

% Dimension size tests
function runJavaMemoryCheck(self)
lastwarn('');
bfCheckJavaMemory(self.minMemory)
[last_warning_msg, last_warning_id] = lastwarn;
assertEqual(last_warning_id, self.warning_id);
self.assertEqual(last_warning_id, self.warning_id);
lastwarn('');
end

end

methods (Test)
function testZero(self)
self.minMemory = 0;
self.runJavaMemoryCheck()
end

function testMaxMemory(self)
self.minMemory = self.getRuntime();
self.runJavaMemoryCheck()
end

function testLowMemory(self)
self.minMemory = round(self.getRuntime() + 100);
self.warning_id = 'BF:lowJavaMemory';
self.runJavaMemoryCheck()
end
end

methods(Static)

function memory = getRuntime()
runtime = java.lang.Runtime.getRuntime();
memory = runtime.maxMemory() / (1024 * 1024);
end
end

end
41 changes: 20 additions & 21 deletions test/TestBfCheckJavaPath.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,37 @@


classdef TestBfCheckJavaPath < TestBfMatlab

properties
status
version
maxTime = .1
end

methods
function self = TestBfCheckJavaPath(name)
self = self@TestBfMatlab(name);
end


methods (Test)
function testDefault(self)
javaaddpath(self.jarPath);
self.status = bfCheckJavaPath();
assertTrue(self.status);
self.assertTrue(self.status);
end

function testAutoloadBioformats(self)
javaaddpath(self.jarPath);
self.status = bfCheckJavaPath(true);
assertTrue(self.status);
self.assertTrue(self.status);
end

function testNoAutoloadBioformats(self)
isStatic = ismember(self.jarPath,...
javaclasspath('-static'));
self.status = bfCheckJavaPath(false);
if isStatic
assertTrue(self.status);
self.assertTrue(self.status);
else
assertFalse(self.status);
self.assertFalse(self.status);
end
end

function testPerformance(self)
nCounts = 10;
times = zeros(nCounts);
Expand All @@ -68,27 +66,28 @@ function testPerformance(self)
bfCheckJavaPath();
times(i) = toc;
end

% First call should be the longest as the Bio-Formats JAR file is
% added to the javaclasspath
assertTrue(times(1) > times(2));
self.assertTrue(times(1) > times(2));
% Second call should still be longer than all the following
% ones. Profiling reveals some amount of time is spent while
% computing javaclasspath.local_get_static_path
assertTrue(all(times(2) > times(3:end)));
self.assertTrue(all(times(2) > times(3:end)));
% From the third call and onwards, javaclasspath and thus
% bfCheckJavaPath should return fast
assertTrue(mean(times(3:end)) < self.maxTime);
self.assertTrue(mean(times(3:end)) < self.maxTime);
end

function testJavaMethod(self)
javaaddpath(self.jarPath);
self.status = bfCheckJavaPath(true);
version = char(loci.formats.FormatTools.VERSION);
[self.status self.version]= bfCheckJavaPath(false);
assertEqual(self.version,version);
self.assertEqual(self.version,version);
if (exist ('OCTAVE_VERSION', 'builtin'))
version = char(java_get('loci.formats.FormatTools', 'VERSION'));
assertEqual( self.version, version);
self.assertEqual( self.version, version);
end
end
end
Expand Down
Loading