Jump to content

Abstract classes for testing code?


Recommended Posts



I went to a new job meeting today and the guy there told me that they use abstract classes for testing classes/codes. Well I would create a simple html file and test the classes and functions if they return me the correct values. So why would i need an abstract class for testing purpose? Is there any point that i am missing, or he does not know what he talks about?


Thank you in advance for your replies.

Link to comment
Share on other sites

What do you mean by "create a simple html file and test the classes"?
A html file would not run your php code; are you talking about implementing a simple view and doing manual testing, or making the html file call endpoints and do end-to-end testing?


Either way sounds as if it's not enough to test code well.

Manual testing is pretty expensive, as in it takes a lot of time, and only reliable in some aspects.


It's much more important to have good automated tests.

Automated tests allow you to write test-first (TDD) code, which is a very effective way to reduce bugs.



I'm not sure what they mean by using abstract classes. It sounds a bit weird.

Are they saying they extends an abstract base class? (Like PhpUnit's TestCase class) That would make more sense.


You can then extend that abstract class and use its assertion methods to test your code. For an example, take a look at these.

Edited by Stratadox
Link to comment
Share on other sites

My mistake. I was gonna say a simple php file. I meant (i m not a php expert), at the last place I was working, we were creating simple php files, set the values in and call the classes and functions and see the results. It was a small company.


It sounded me weird too when the guy told me that, I don't need to make the class abstract to test the code (as far as i know). So what's the point. Well I think he does not know what he talks about.

Link to comment
Share on other sites

Just a guess, abstract class -> abstract method, this way you're always got the error checking code running before you access the rest of the classes/methods. So any instance will automatically call the error method first etc.


Link might be helpful (Even if Java): http://www.javacoffeebreak.com/faq/faq0084.html

Edited by BigB
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.