Skip to content

Commit

Permalink
Feature 539 add test workflow (#548)
Browse files Browse the repository at this point in the history
* added the test.yaml for initial JUnit tests and changed filenames of the other GHA workflow files to conform with the rest of METplus

* Issue #539 add this jar to enable GHA to run junit

* Issue #539 including the edu/ucar/metviewer/test/mvutil/*.java to the target "compile-all"

* Test if junit command works

* Fixed syntax error

* Added test-compile and test to facilitate JUnit4 tests

* Use test-compile and test target in the command

* use ant test command instead of java -jar to run junit test

* fix lib to ${lib} for junit jar and modify some paths for the test build dir

* modify the ant command to run the test

* remove incorrect/unused ant command for compiling tests

* explicitly point to the MVUtil tests

* experiment with running the junit-platform-console-standalone jar

* Separate the first run command into building the tests

* Added some useful comments, cleaning up

* Simple JUnit test and runner used to create the test.yaml GHA workflow
  • Loading branch information
bikegeek authored Sep 18, 2024
1 parent 7fa7a20 commit 0030eca
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a Java project with Ant
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-ant

name: JUnit CI

on:
push:
branches:
- develop
- develop-ref
- feature_*
- issue_*
- main_*
- bugfix_*
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Build MV JUnit tests
run: ant clean test -verbose -noinput
- name: Run MV JUnit tests
run: java -jar lib/junit-platform-console-standalone-1.4.0.jar --select-package edu.ucar.metviewer.test.mvutiljava
46 changes: 45 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="src.webapp.dir" location="webapp"/>
<property name="test.build.dir" location="build/edu/ucar/metviewer/test"/>
<property name="test.src.dir" location="java/edu/ucar/metviewer/test"/>


<!-- Initialize the build tree -->
Expand Down Expand Up @@ -245,6 +247,15 @@
<pathelement location="${lib}/snakeyaml-1.27.jar"/>
</path>

<path id="classpath.test">
<pathelement location="${lib}/junit-4.11.jar"/>
<pathelement location="${lib}/hamcrest-core-1.3.jar"/>
<pathelement location="${lib}/mockito-all-1.9.5.jar"/>
<pathelement location="${lib}/junit-platform-console-standalone-1.4.0.jar"/>
<pathelement location="${build}"/>

</path>

<target name="test.db.management.system">
<condition property="db.management.system.mysql">
<equals arg1="${db.management.system}" arg2="mysql"/>
Expand Down Expand Up @@ -301,6 +312,38 @@
<classpath refid="${db.management.system}-all"/>
</javac>
</target>

<!-- JUnit tests -->
<target name="test-compile" depends="compile, compile-all">
<javac srcdir="${test.src.dir}"
destdir="${test.build.dir}"
includeantruntime="true"
nowarn="yes"
debug="true">
<classpath refid="classpath.test"/>
<include name="edu/ucar/metviewer/test/**Test" />
</javac>
<property name="d" refid="classpath.test"/>
<echo>classpath.test = ${d}</echo>

</target>

<target name="test" depends="test-compile">
<junit printsummary="on" haltonfailure="yes" fork="true">
<classpath >
<path refid="classpath.test"/>
<pathelement location="${test.build.dir}"/>
</classpath>

<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.build.dir}">
<include name="TestMVUtil*"/>
<!-- Include other JUnit tests as they are created-->
</fileset>
</batchtest>
</junit>
</target>

<!-- Create the distribution directory -->
<target name="dist" depends="compile"
Expand All @@ -319,7 +362,7 @@
</copy>
<delete file="${build}/MANIFEST.MF"/>
<manifest file="${build}/MANIFEST.MF">
<attribute name="Specification-Version" value="6.0.0-beta5-dev"/>
<attribute name="Specification-Version" value="6.0.0-beta6-dev"/>
</manifest>

<jar jarfile="${dist}/lib/metviewer.jar" basedir="${build}" manifest="${build}/MANIFEST.MF">
Expand Down Expand Up @@ -437,6 +480,7 @@
<exclude name="junit-4.11.jar"/>
<exclude name="hamcrest-core-1.3.jar"/>
<exclude name="mockito-all-1.9.5.jar"/>
<exclude name="junit-platform-console-standalone-1.4.0.jar"/>
</fileset>
</copy>
<copy todir="${dist}/metviewer/WEB-INF/lib"
Expand Down
30 changes: 30 additions & 0 deletions java/edu/ucar/metviewer/test/mvutil/TestMVUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.ucar.metviewer.test.mvutil;

import edu.ucar.metviewer.MVUtil;
import org.junit.Test;

import org.junit.runner.notification.Failure;
import org.w3c.dom.Document;



import static org.junit.Assert.*;


public class TestMVUtil {
@Test
public void testCreateDocument(){
try{
System.out.println("Testing CreateDocument...");
assertTrue(MVUtil.createDocument() instanceof Document );
assertTrue(MVUtil.createDocument() != null);

}catch (javax.xml.parsers.ParserConfigurationException e){
fail("ParserConfigurationException was raised while creating a document");
}
}




}
23 changes: 23 additions & 0 deletions java/edu/ucar/metviewer/test/mvutil/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.ucar.metviewer.test.mvutil;

import com.sun.net.httpserver.Authenticator;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;


// Useful for running from the command line


public class TestRunner {
public static void main(String[] args){
Result result = JUnitCore.runClasses(TestMVUtil.class);

for (Failure failure : result.getFailures()){
System.out.println(failure.toString());
}

System.out.println("Tests pass: "+ result.wasSuccessful() + "\nNumber of runs: " +
result.getRunCount());
}
}
Binary file added lib/junit-platform-console-standalone-1.4.0.jar
Binary file not shown.

0 comments on commit 0030eca

Please sign in to comment.