mohammadkaab's avatar

Automatically checks if code contains test or not

Hi guys

I'm wondering if there is a way to automatically check the pull-requests code and also check if the code contains tests.

0 likes
2 replies
ChristophHarms's avatar
Level 18

This is a little too little information. Where do you want to check that? Do you have an own BuildServer? Or do you use something like Circle-CI? Or do you have an own git-repo on an own server?

Of course there are ways to see if there are tests in the code (we are devs, we can do anything we want with code ;) ), but I don't think it's sensible to do so. You could, for example, parse the whole codebase and check for classes that extend PHPUnit_Testcase. But that's pretty expensive, depending on how big your codebase is. Or, if you put all your tests in a specific directory by convention, you could write a script that checks that directory. As you see, this is all strongly coupled to how your codebase is organized and on your conventions.

If you just want to make sure to make sure that no one pushes new code without tests for said code, it'd be easier to measure the code coverage and have a CI Job that fails if coverage goes down. If someone removes a previously existent test: coverage goes down -> CI fails. If someone pushes new code without tests: coverage goes down -> CI fails.

Please or to participate in this conversation.