How can I test func main
? Like this:
func main(){
Engine := GetEngine() // returns gin router with handlers atttached
Engine.Run(":8080")
}
It has only 2 lines but I'd like to have them covered.
TestMain'
is reserved for test preparation, does that mean testing main
was not planned by language creators?
I can move the contents to another function mainReal
but it seems to be some over engineering?
How to test gin has started well? Can I launch main
in separate goroutine, check reply and stop it?
Thanks.
P.S. Possible duplicate is not precise duplicate because it is dedicated not to testing of func main()
itself, but rather ideas to move in outside and so contains different issue and approach.