Executing Junit tests in gradle

To use JUnit in your Gradle project, you will have to use below dependency.
 
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
We can execute the JUnit tests in a Gradle project by issuing below command.

gradle test

By default, this command will execute all test classes that end with Test or Tests To execute tests from specific classes

test –tests=junit.SimpleSuite

To execute tests from all classes in specific package

test –tests=junit.*

To execute specific test method

test –tests=junit.SimpleSuite.test2

To execute tests from specific category You need to use build.gradle file to specify the categories to be included and excluded. For example – In below configuration, all tests belonging to category CategoryX will be executed.

test{
    useJUnit {
    includeCategories 'categories.CategoryX'
    excludeCategories 'categories.CategoryY'
    }
}

Web development and Automation testing

solutions delivered!!