Hi Team,
I have a workflow with 4 activities and I have specified to not retry a particular exception in my activity options in the workflow.
However when I create the TestWorkflowExtension as below
@RegisterExtension
@JvmField
val testWorkflowExtension: TestWorkflowExtension = TestWorkflowExtension.newBuilder()
.setWorkerOptions(WorkerOptions { WorkflowImplementationOptions{
setDefaultActivityOptions(ActivityOptions { RetryOptions{ setDoNotRetry(NoSuchElementException::class.java.name) } })}
})
.setWorkflowTypes(ExpenseCategoryWorkflowImpl::class.java)
.setDoNotStart(true)
.build()
and in my test when I throw this NoSuchElementException
, the test doesn’t pass and workflow execution doesn’t say completed. Though I know this is how it behaves in real scenario from my manual tests.
@Test
fun `automate expense category workflow is successful`(
testEnv: TestWorkflowEnvironment, worker: Worker, workflow: ExpenseCategoryWorkflow
) {
val activity: ExpenseCategoryActivity = Mockito.mock(ExpenseCategoryActivity::class.java)
whenever(activity.getCategoriesForExpense(getCategoryForExpenseInputDTO)).then{throw NoSuchElementException()}
worker.registerActivitiesImplementations(activity)
testEnv.start()
assertDoesNotThrow {
workflow.automateExpenseCategory(expenseInputDTO)
}
verify(activity).getCategoriesForExpense(getCategoryForExpenseInputDTO)
}
what am I missing here? This is an extension of the questions asked in this thread Testing pattern for Temporal Workflow - Java