Giter VIP home page Giter VIP logo

grails403test's Introduction

Project Description

A simple project to demonstrate a failed unit test for controller

Controller class and the test

class TestController {
    def testJson(){
        def json = request.JSON
        render(contentType:'application/json', text:json.toString(), encoding: "UTF-8")
    }
}
class TestControllerSpec extends Specification implements ControllerUnitTest<TestController> {

    def setup() {
    }

    def cleanup() {
    }

    void "test json"(){
        when:
        request.json = [
                a:1, b:2, c:3
        ]
        controller.testJson()

        then:
        response.json.a == 1
        response.json.b == 2
        response.json.c == 3

        when:
        response.reset()
        request.json = [
                a:10, b:20, c:30
        ]
        controller.testJson()

        then:
        response.json.a == 10 // <-- test failed here
        response.json.b == 20
        response.json.c == 30
    }
}

Requirement

Use SDK Man to install java and GRAILS, e.g.

$ sdk install java 8.0.252-zulu
$ sdk install grails 4.0.3

Run the test

$ cd Grails403Test
$ grails test-app

Output

Condition not satisfied:

response.json.a == 10 // <-- test failed here
|        |    | |
|        |    1 false
|        [a:1, b:2, c:3]

grails403test's People

Contributors

jaguar1975cn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.