0

I am a beginner with Serenity Junit. I am trying to clarify if there is any way to execute a single test of a specified test class via mvn command-line? I also tried with mvn clean verify -Dtest="com.studentapp.junit.studentsinfo.StudentsCRUDTest" but all of my tests were executed instead of only the tests in StudentsCRUDTest class.

As you see in my capture, there is only one test in my StudentsCRUDTest class enter image description here

Your help to clarify my concern would be extremely appreciated from my indeed. Thanks

Hakan Dilek
  • 2,178
  • 2
  • 23
  • 35
  • 1
    mvn test -Dtest=StudentsCRUDTest base on https://stackoverflow.com/questions/1873995/run-a-single-test-method-with-maven – Maroine Mlis Jul 04 '21 at 13:03
  • Thank you very much for your information @MaroineMlis. I post my comment as another answer below because I am not able to attach my capture Images to the comment session. Thank you very much :) – Nhan Tran Trong Jul 05 '21 at 14:29
  • Thank you for your link also @KristofNeirynck. Your link is also really informative to me, but the comment session is not allowed to tag 2 usernames in the same comment hihi :) – Nhan Tran Trong Jul 05 '21 at 14:29

2 Answers2

1

You can run by tag:

$ mvn clean verify -Dtags="your-tag"

refer: https://johnfergusonsmart.com/running-serenity-bdd-tests-with-tags/

lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
  • Thank you very much for your suggestion @lucasnguyen17. I was able to execute a single test by tag successfully. In my question, I would like to find some way to execute my single test via command line for debugging or investigating purposes, I don't want to add a tag (ex: `development:in-progress`) whenever I would like to re-run or debug my single test. – Nhan Tran Trong Jul 05 '21 at 13:56
0

Thank you very much for your information @MaroineMlis and @Kristof Neirynck, I found the root cause from your suggested links. It works like a charm when I update the maven-surefire plugins configuration in my POM as below: My POM file before updating

My POM file after updating

  • 1
    Serenity bdd uses failsafe plugin, not surefire, so I guess you can run the test but no serenity report. – lucas-nguyen-17 Jul 05 '21 at 14:31
  • Serenity report is also generated normally with my following command @lucasnguyen17`mvn clean test -Dtest=com.studentapp.junit.createStudent.CreateStudentTest serenity:aggregate` – Nhan Tran Trong Jul 05 '21 at 14:33
  • @lucasnguyen17, Thank you for your information. I found the answer here https://stackoverflow.com/questions/53377534/start-single-serenity-scenario-from-command-line. When using failsafe, we need to use `mvn verify -Dit.test=className#testMethodName` instead of `mvn test -Dtest=className#testMethodName` as maven surefire – Nhan Tran Trong Jul 05 '21 at 15:09