@@ -131,8 +131,20 @@ trait CucumberSuite extends Suite {
131131 " Running a single test by name is not supported in CucumberSuite"
132132 )
133133 }
134- context.runFeatures(() => super .run(testName, args))
135- org.scalatest.SucceededStatus
134+ var status : Status = org.scalatest.SucceededStatus
135+ try {
136+ context.runFeatures(() => {
137+ println(s " About to call super.run " )
138+ status = super .run(testName, args)
139+ println(s " super.run returned status: $status, succeeds= ${status.succeeds()}" )
140+ })
141+ } catch {
142+ case ex : Throwable =>
143+ println(s " CucumberSuite.run caught exception: ${ex.getClass.getName}: ${ex.getMessage}" )
144+ throw ex
145+ }
146+ println(s " CucumberSuite.run returning status: $status, succeeds= ${status.succeeds()}" )
147+ status
136148 }
137149
138150 private def buildRuntimeOptions (): RuntimeOptions = {
@@ -216,8 +228,17 @@ trait CucumberSuite extends Suite {
216228 }
217229
218230 override def run (testName : Option [String ], args : Args ): Status = {
231+ println(s " FeatureSuite.run called " )
219232 context.beforeFeature(feature)
220- super .run(testName, args)
233+ try {
234+ val status = super .run(testName, args)
235+ println(s " FeatureSuite.run returning status: $status, succeeds= ${status.succeeds()}" )
236+ status
237+ } catch {
238+ case ex : Throwable =>
239+ println(s " FeatureSuite.run caught exception: ${ex.getClass.getName}: ${ex.getMessage}" )
240+ throw ex
241+ }
221242 }
222243 }
223244
@@ -229,26 +250,39 @@ trait CucumberSuite extends Suite {
229250
230251 override def suiteName : String = pickle.getName
231252
232- override def testNames : Set [String ] = Set (pickle.getName )
253+ override def testNames : Set [String ] = Set (" scenario " )
233254
234- override protected def runTest (
235- testName : String ,
236- args : Args
237- ): Status = {
255+ override def run (testName : Option [String ], args : Args ): Status = {
238256 var testFailed : Option [Throwable ] = None
239257
258+ // Execute the test
240259 context.runTestCase(runner => {
241- try {
242- runner.runPickle(pickle)
243- } catch {
244- case ex : Throwable =>
245- testFailed = Some (ex)
260+ // Subscribe to TestCaseFinished events to detect failures
261+ val handler = new io.cucumber.plugin.event.EventHandler [io.cucumber.plugin.event.TestCaseFinished ] {
262+ override def receive (event : io.cucumber.plugin.event.TestCaseFinished ): Unit = {
263+ val result = event.getResult
264+ if (! result.getStatus.isOk) {
265+ val error = result.getError
266+ if (error != null ) {
267+ testFailed = Some (error)
268+ } else {
269+ testFailed = Some (new RuntimeException (s " Test failed with status: ${result.getStatus}" ))
270+ }
271+ }
272+ }
246273 }
274+ runner.getBus.registerHandlerFor(classOf [io.cucumber.plugin.event.TestCaseFinished ], handler)
275+
276+ runner.runPickle(pickle)
247277 })
248278
249279 testFailed match {
250- case Some (ex) => throw ex
251- case None => org.scalatest.SucceededStatus
280+ case Some (ex) =>
281+ println(s " PickleSuite.run returning FailedStatus for: ${ex.getMessage}" )
282+ org.scalatest.FailedStatus
283+ case None =>
284+ println(s " PickleSuite.run returning SucceededStatus " )
285+ org.scalatest.SucceededStatus
252286 }
253287 }
254288 }
0 commit comments