我想要获得测试覆盖率,并与用户定义的阈值进行比较.我在Makefile中try 了下面的代码,我引用了这个link.它是在.yml文件中编写的,但我正在try 将其写入Makefile中.
.PHONY: lint
testcoverage=$(go tool cover -func coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
echo ${testcoverage}
if (${testcoverage} -lt 50 ); then \
echo "Please add more unit tests or adjust threshold to a lower value."; \
echo "Failed"
exit 1
else \
echo "OK"; \
fi
它不会在echo ${totaltestcoverage}
上打印任何内容,即使我的总覆盖率是40,它的答案也是OK.
有谁能帮我找到一种更好的方法来获得测试覆盖率,并与用户定义的阈值进行比较?
先谢谢你.