public static Stream < DynamicTest > packageScan ( String ... packagesToScan ) { List < DynamicTest > tests = new ArrayList <> ( ) ; for ( String packageScan : packagesToScan ) { try { for ( String fileNamePattern : Citrus . getXmlTestFileNamePattern ( ) ) { Resource [ ] fileResources = new PathMatchingResourcePatternResolver ( ) . getResources ( packageScan . replace ( ' ' , File . separatorChar ) + fileNamePattern ) ; for ( Resource fileResource : fileResources ) { String filePath = fileResource . getFile ( ) . getParentFile ( ) . getCanonicalPath ( ) ; if ( packageScan . startsWith ( "file:" ) ) { filePath = "file:" + filePath ; } filePath = filePath . substring ( filePath . indexOf ( packageScan . replace ( ' ' , File . separatorChar ) ) ) ; String testName = fileResource . getFilename ( ) . substring ( 0 , fileResource . getFilename ( ) . length ( ) - ".xml" . length ( ) ) ; XmlTestLoader testLoader = new XmlTestLoader ( DynamicTest . class , testName , filePath , citrus . getApplicationContext ( ) ) ; tests . add ( DynamicTest . dynamicTest ( testName , ( ) -> citrus . run ( testLoader . load ( ) ) ) ) ; } } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Unable to locate file resources for test package '" + packageScan + "'" , e ) ; } } return tests . stream ( ) ; }
Creates stream of dynamic tests based on package scan . Scans package for all Xml test case files and creates dynamic test instance for it .