The machine used for the test run must be a Windows machine:
Create a directory in which you will place all the files and all the directories picked up in %ADELIWS%\Unit_Tests\Maven.
import javax.xml.transform.stream.StreamSource
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.Source
import javax.xml.transform.Transformer
import javax.xml.transform.TransformerFactory
apply plugin: 'java'
group = '[ORGANISATION ID]'
version = '[PROJECT VERSION]'
description = "Adelia unitary test"
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
testCompile fileTree(dir: "${System.env.ADELIWS}javarun" , include: '*.jar')
testCompile "junit:junit:4.9"
}
task adelGen {
doLast{
if (System.getProperty("skip.gen.test.pgm") == null) {
exec{
environment "javaSourceDirectory" , "${projectDir}\\src\\test\\java\\"
environment "CLASSPATH" , "${System.env.ADELIWS}javarun;${System.env.ADELIWS}javarun\\*"
//*******************************************************************
environment "adeliaEnvironment" ,"[ENVIRONMENT NAME]"
environment "adeliaTask01" , "[ADELIA TASK NAME]"
//*****************************
environment "winJavaSvrDir" , "[WINDOWS JAVA SERVER DIRECTORY]"
environment "AS400SvrLib" , "[AS/400 SERVER LIBRARY]"
environment "AS400SvrHost" , "[AS/400 SERVER HOST]"
environment "AS400SvrPort" , "[AS/400 SERVER PORT]"
environment "AS400SvrProfile" , "[AS/400 SERVER PROFILE]"
environment "AS400SvrPwd" , "[AS/400 SERVER PASSWORD]"
environment "AS400SvrEncryptPwd" , "[AS/400 SERVER ENCRYPTED PASSWORD]"
environment "AS400SvrJobdLib" , "[AS/400 SERVER JOBD LIBRARY]"
environment "AS400SvrJobdName" , "[AS/400 SERVER JOBD NAME]"
//*******************************************************************
executable "AGPTS.exe"
}
}
else {
copy{
from "${System.env.ADELIWS}CHKTSTREF.java"
into "${projectDir}\\src\\test\\java\\com\\hardis\\adelia\\test"
rename 'CHKTSTREF.java' , 'CHKTST.java'
}
}
}
}
compileTestJava.mustRunAfter(adelGen)
// **********************************************************************
task [GRADLE TASK NAME](type : Test , dependsOn: adelGen ) {
group 'adeliaUnitTest'
ignoreFailures true
systemProperty 'adeliaPhysicalServerHost', '[MIDDLEWARE SERVER]'
systemProperty 'adeliaPhysicalServerPort', '[PORT]'
systemProperty 'adeliaPhysicalServerProfile', '[MIDDLEWARE PROFILE]'
systemProperty 'adeliaPhysicalServerPassword', '[PASSWORD]'
systemProperty 'adeliaLogicalServer', '[LOGICAL SERVER NAME]'
systemProperty 'adeliaDatabase', '[DB TEST NAME]'
include '**/*.class'
exclude 'com/hardis/adelia/test/CHKTST.class'
}
// ***********************************************************************
test {
systemProperty 'adeliaTestType', 'gradle'
systemProperty 'reportDirectory' , "${projectDir}\\build\\test-results\\"
systemProperty 'noXslStyleSheet', 'true'
include 'com/hardis/adelia/test/CHKTST.class'
}
gradle.taskGraph.afterTask { task, state →
if ( task.name == "test") {
def xslt= new File("${System.env.ADELIWS}AdeliaTestsReport.xsl").getText()
def transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(xslt)))
def xml= new File("${projectDir}/build/test-results/AdeliaTestsReport.xml").getText()
def html = new FileOutputStream("${projectDir}/build/test-results/AdeliaTestsReport.html")
transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(html))
logger.lifecycle("Global test Report: file:///${projectDir}/build/test-results/AdeliaTestsReport.html")
}
}
test.dependsOn {tasks.findAll { task -> task.group == "adeliaUnitTest" }}
|
The following parameters are not strictly speaking Framework parameters but are an illustration of the method used to transmit contextual information from the build.gradle file to the test programs.
In this case, these parameters are used to manage the dynamic Middleware connection used by the TEST_CONFIG management rule.
|
If you need more execution contexts for your tests, you can add a second execution block. To do this:
If some test programs must run in a particular execution context (and then for a specific test task) and not in another, you can set this particular case using <include> and <exclude> tags, naming the java class path directly.
Be sure to use / instead of a dot in the package.
You can use generic names with regard to a package (e.g. com/mestests/AS400/*.java): if you put your test programs in different tasks, they can have a different package even if they are in the same application area.
Caution: if your test programs have AS/400 server parts, you must be, on your AS/400, at least at the level of PTF F003 of the AS/400 part of Adelia Studio 13.
To run the test, open a Windows command window, navigate to the directory of your test project (the one that contains your build.gradle file) and run the following command:
gradlew clean test
Note: when you first run the command, your machine must have an Internet access so that Gradle can download some components cited in the build.gradle file.
If no error is detected during the preparatory phase of the tests (analysis of the build.gradle file and generation of test programs) you will find the unit test report files AdeliaTestsReport.xml and AdeliaTestsReport.html in your test project directory in the "build/test-results" directory.
The AdeliaTestsReport.html presents the results as shown below:
Notes:
If the "noXslStyleSheet"; property of the ";test"; task is set to 'false', then the AdeliaTestsReport.xml file will be associated with a style sheet (AdeliaTestsReport.xsl) which allows the results to be presented in the Microsoft Edge or FireFox browser, in the same way as in the AdeliaTestsReport.html document (caution: local style sheets are not accepted by the Chrome browser).
If you want to rerun the same tests as those carried out during the previous run, but skipping the step of generating test programs, you can do this by running the following command:
gradlew -Dskip.gen.test.pgm=true clean test
Errors related to executing the plug-in: org.codehaus.mojo: exec-maven-plugin
-1 to -4: Errors related to the ADELJOB command
-5: Generating or compiling a test program has failed (open the job manager for more information about the error)
-10: A task specified in an adeliaTaskxx tag does not exist in the environment
-11: A task specified in an adeliaTaskxx tag does is not a test type task
-50: Could not load an Adelia product dll
-51: The name of the Adelia environment is not specified in the build.gradle file
-52: Error connecting to the environment
-53: Error retrieving information about the environment.
-55: Error copying the file com/hardis/adelia/test/CHKTST.java under the test project directory