Skip to content

Commit

Permalink
get configuration dynamically handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan108 committed Aug 5, 2024
1 parent a9da128 commit 041a505
Showing 1 changed file with 72 additions and 61 deletions.
133 changes: 72 additions & 61 deletions src/main/kotlin/com/featurevisor/testRunner/TestExecuter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,51 @@ data class TestProjectOption(
val projectRootPath: String? = null
)

fun startTest(option: TestProjectOption) {
option.projectRootPath?.let { it ->
val projectConfig = parseConfiguration(it)
var hasError = false
val folder = File(projectConfig.testsDirectoryPath)
val listOfFiles = folder.listFiles()?.sortedBy { it }
var executionResult: ExecutionResult? = null
val startTime = System.currentTimeMillis()
var passedTestsCount = 0
var failedTestsCount = 0
var passedAssertionsCount = 0
var failedAssertionsCount = 0
val datafileContentByEnvironment: MutableMap<String, DatafileContent> = mutableMapOf()

if (option.fast) {
for (environment in projectConfig.environments) {
val datafileContent = buildDataFileAsPerEnvironment(option.projectRootPath,environment)
datafileContentByEnvironment[environment] = datafileContent
}
fun startTest(option: TestProjectOption) = option.projectRootPath?.let { it ->
val projectConfig = parseConfiguration(it)
var hasError = false
val folder = File(projectConfig.testsDirectoryPath)
val listOfFiles = folder.listFiles()?.sortedBy { it }
var executionResult: ExecutionResult?
val startTime = System.currentTimeMillis()
var passedTestsCount = 0
var failedTestsCount = 0
var passedAssertionsCount = 0
var failedAssertionsCount = 0
val datafileContentByEnvironment: MutableMap<String, DatafileContent> = mutableMapOf()

if (option.fast) {
for (environment in projectConfig.environments) {
val datafileContent = buildDataFileAsPerEnvironment(
projectRootPath = it,
environment = environment
)
datafileContentByEnvironment[environment] = datafileContent
}
}

if (!listOfFiles.isNullOrEmpty()) {
for (file in listOfFiles) {
if (file.isFile) {
if (file.extension.equals("yml", true)) {
val filePath = file.absoluteFile.path
if (listOfFiles.isNotEmpty()){
executionResult = executeTest(filePath, datafileContentByEnvironment, option, projectConfig)
if (executionResult == null) {
continue
}

if (executionResult.passed) {
passedTestsCount++
} else {
hasError = true
failedTestsCount++
}
if (!listOfFiles.isNullOrEmpty()) {
for (file in listOfFiles) {
if (file.isFile) {
if (file.extension.equals("yml", true)) {
val filePath = file.absoluteFile.path
if (listOfFiles.isNotEmpty()) {
executionResult = try {
executeTest(filePath, datafileContentByEnvironment, option, projectConfig)
} catch (e: Exception) {
printMessageInRedColor("Exception while executing assertion -> ${e.message}")
null
}
if (executionResult == null) {
continue
}

if (executionResult.passed) {
passedTestsCount++
} else {
hasError = true
failedTestsCount++
}

passedAssertionsCount += executionResult.assertionsCount.passed
failedAssertionsCount += executionResult.assertionsCount.failed
Expand All @@ -59,38 +66,43 @@ fun startTest(option: TestProjectOption) {
}
}
}
}

val endTime = System.currentTimeMillis() - startTime
val endTime = System.currentTimeMillis() - startTime

if (!option.onlyFailures || hasError) {
printNormalMessage("\n----")
}
printNormalMessage("")

if (hasError) {
printMessageInRedColor("\n\nTest specs: $passedTestsCount passed, $failedTestsCount failed")
printMessageInRedColor("Test Assertion: $passedAssertionsCount passed, $failedAssertionsCount failed")
} else {
printMessageInGreenColor("\n\nTest specs: $passedTestsCount passed, $failedTestsCount failed")
printMessageInGreenColor("Test Assertion: $passedAssertionsCount passed, $failedAssertionsCount failed")
}
printBoldMessage("Time: ${prettyDuration(endTime)}")
if (!option.onlyFailures || hasError) {
printNormalMessage("\n----")
}
printNormalMessage("")

if (hasError) {
printMessageInRedColor("\n\nTest specs: $passedTestsCount passed, $failedTestsCount failed")
printMessageInRedColor("Test Assertion: $passedAssertionsCount passed, $failedAssertionsCount failed")
} else {
printMessageInRedColor("Directory is Empty or not exists")
printMessageInGreenColor("\n\nTest specs: $passedTestsCount passed, $failedTestsCount failed")
printMessageInGreenColor("Test Assertion: $passedAssertionsCount passed, $failedAssertionsCount failed")
}
} ?: printNormalMessage("Root Project Path Not Found")
printBoldMessage("Time: ${prettyDuration(endTime)}")
} else {
printMessageInRedColor("Directory is Empty or not exists")
}
} ?: printNormalMessage("Root Project Path Not Found")

}

private fun executeTest(filePath: String, datafileContentByEnvironment:MutableMap<String, DatafileContent>, option: TestProjectOption,configuration: Configuration): ExecutionResult? {
private fun executeTest(
filePath: String,
datafileContentByEnvironment: MutableMap<String, DatafileContent>,
option: TestProjectOption,
configuration: Configuration
): ExecutionResult? {
val test = parseTestFeatureAssertions(filePath)

val executionResult = ExecutionResult(
passed = true,
assertionsCount = AssertionsCount(0, 0)
)

if (test != null){
if (test != null) {
val key = when (test) {
is Test.Feature -> test.value.key
is Test.Segment -> test.value.key
Expand All @@ -110,12 +122,11 @@ private fun executeTest(filePath: String, datafileContentByEnvironment:MutableMa
}

is Test.Segment -> {
// testSegment(
// testSegment = test.value,
// configuration = configuration,
// option = option
// )
testSegment(test.value, configuration)
testSegment(
testSegment = test.value,
configuration = configuration,
option = option
)
}
}

Expand Down

0 comments on commit 041a505

Please sign in to comment.