Tuesday, 16 May 2017

Junit and TestNG

1. junit

2. junit folder structure (automatically created when create maven project in eclipse)
      module/
            src/
                  main/
                        java/
                  test/
                        java/

3. common issue 1
  • package org.junit does not exist' even though dependency added in pom.xml
  • root cause: in eclipse you default select create 'new junit 4 test', then in pom.xml you choose junit version '4.11' instead of '3.8.1'
4. common issue 2
  • if @Test use: public class xxxTest extends TestCase {}, it is junit 3
  • then you see error 'No tests found in package'
  • root cause: in junit 4, should use public class xxxTest {}
5. common issue 3
  • unknown lifecycle phase "Maven". you must specify a valid lifecycle phase or a goal
  • root cause: in eclipse the goal for maven run configuration should be e.g. 'test' instead of 'maven test'

reference
1. junit faq
2. unit testing with Junit - tutorial
3. youtube junit setup

No comments:

Post a Comment