Giter Club home page Giter Club logo

Comments (6)

archsword avatar archsword commented on June 26, 2024 1

So, the problem is that I have is that I have many tests that do a GET to check the state, POST to change the state, and GET to confirm the state changed. And if one of the GET fails, I don't know which one it is because there is no label and they look identical. So, it means always having to lookup the line number for failing tests, which is particularly time-consuming because this is used in continuous integration tests and so I have to first find the commit it is in so that the line number is correct. If you have any recommendations, I would greatly appreciate it. This tool has been wonderful to use as supports everything I could even think of asking.

from apitest.

archsword avatar archsword commented on June 26, 2024 1

That looks great!

from apitest.

steinfletcher avatar steinfletcher commented on June 26, 2024

Hey @archsword. The name is currently only used in reports, e.g. sequence diagrams. I think currently you'd identify failed tests using the standard go test name. If you aren't using the sequence diagrams it's probably easier to not use the New() method, tbh it's not the nicest API and I added the Handler method later to simplify creation, e.g

apitest.Handler(handler).
		Post("/hello").
		Body(`{"a": 12345}`).
		Header("Content-Type", "application/json").
		Expect(t).
		Status(http.StatusOK).
		End()

from apitest.

steinfletcher avatar steinfletcher commented on June 26, 2024

@archsword thanks for more info. Understood. I'll look into it and get back to you.

If you aren't already aware, Debug() is very useful for getting some visibility into failing tests. It prints the http headers and payload of all interactions.

func TestApiTest_ResponseBody(t *testing.T) {
	apitest.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		_, _ = w.Write([]byte(`{"id": "1234", "name": "Andy"}`))
		w.WriteHeader(http.StatusOK)
	}).
		Debug().
		Get("/user/1234").
		Expect(t).
		Body(`{"id": "1234", "name": "Andy"}`).
		Status(http.StatusOK).
		End()
}

from apitest.

steinfletcher avatar steinfletcher commented on June 26, 2024

How about something like this? It'll require a little bit of a refactor but should be possible.

Screenshot 2022-09-16 at 09 41 50

from apitest.

steinfletcher avatar steinfletcher commented on June 26, 2024

I have a branch with the changes if you want to take it for a spin, otherwise I think I'll look to merge it over the weekend some time.

https://github.com/steinfletcher/apitest/tree/feature/test-case-name

from apitest.

Related Issues (20)

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.