TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Karate

Run Karate Test with JUnit5

Overview

In this tutorial, we will learn how to Run Karate Test with JUnit 5 framework. To create a Karate automation Maven Archetype project follow the link:

https://www.testingdocs.com/create-karate-automation-project/

Maven dependency

Karate Junit5 Maven dependency. Add this to the Maven pom.xml file and update the project. Maven would automatically add Karate Junit 5 support to the project.

<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>

 

Cucumber Feature

In this tutorial, we will test MantisBT Rest API call to create an issue using HTTP Post method. To know more about the REST API endpoint:

https://www.testingdocs.com/mantisbt-rest-api-guide/

Add a BDD .feature file (aka .story file) to automate the Rest API call. There is no code required to write the step definitions. We just need to add the Gherkin as per the Karate DSL.

—

#Author: www.TestingDocs.com

#Sample Feature Definition Template

Feature: Post Mantis Issue
I want to test POST Mantis API call

@Mantis
Scenario: Create MantisBT Issue
Given url ‘http://localhost/mantis/api/rest/issues/’
And header Authorization = ‘<Access Token>’
And request { “summary”: “This issue created using Karate Tool-JUnit5 Demo”, “description”:                      “[TestingDocs.com]Issue Description sample test bug API”, “category”: { “name”: “General” },

“project”: { “name”: “TestingDocsProject” } }
When method POST
Then status 201

—

 

MantisBT Post Feature

 

In the feature file, we assert for HTTP response code 201. This implies that MantisBT issue is created in the bug tracker tool. In real testing scenarios, we can add further checks and validations to the API JSON Response with JsonPath expressions.

Run Karate Test

Add a runner Java class with Karate Junit 5 test. Annotate the test with the annotation

@Karate.Test

package com.testingdocs.karate.demo;

import com.intuit.karate.junit5.Karate;

class MantisIssueRunner {

 @Karate.Test
 Karate testPostIssue() {
 return Karate.run("mantisPostIssue").relativeTo(getClass());
 }
}

Karate Junit5 Test

Run JUnit Test

Run the test. Right click Run as >> Junit Test

JUnit 5 Test

 

–

Karate Automation Tutorials

Karate tool tutorials on this website can be found at:

https://www.testingdocs.com/karate-automation-tool-tutorials/

More information on the tool:

https://github.com/intuit/karate

Related Posts

Multiple Threads Karate Automation

Karate /

Parallel Test Execution using Karate DSL

Get API Request

Karate /

Test GET API Request with Karate DSL

New Feature File Karate

Karate /

Create Karate API Test Script( Feature File )

Karate /

CRUD Operations API Test Automation with Karate

Data Driven Testing Karate

Karate /

Data Driven Testing using Karate Automation Tool

‹ Karate API Automation Reports› Testing POST Request with Karate Framework

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version