Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat do you call an inner class used for testing?
    primarykey
    data
    text
    <p>Our team has members who are just ramping up on unit testing and we're struggling with some terminology. I'd like to determine a name for a particular pattern. I'm hoping there's one that's already embraced by other developers, but if not, I'd like to come up with one that's descriptive and will make talking about test strategies easier.</p> <p>This pattern is used quite a bit for testing abstract methods, but is also handy when an object creates a new object (for cases where DI doesn't work or isn't desired). The basic pattern is to use an inner class that extends the class under test to expose protected methods.</p> <p>Consider the following code (which is pseudocode, based on Java, but should translate to most languages):</p> <p>The class to test:</p> <pre><code>public class MyClass { public void send() { //do something } protected MailMessage createNewMailMessage() { return new MailMessage(); } } </code></pre> <p>The test:</p> <pre><code>public class MyClassTest { private MyClass myClass = new TestableMyClass(); private MailMessage mockMessage = mock(MailMessage.class); public void setup() { ((TestableMyClass)myClass).setMailMessage(mockMessage); } // Do some tests // private class TestableMyClass extends MyClass { private MailMessage mailMessage; public void setMailMessage(MailMessage mailMessage) { this.mailMessage = mailMessage; } protected MailMessage createNewMailMessage() { return mailMessage; } } } </code></pre> <p>So, what do you call this pattern? TestableMyClass a "Mock" object, but since it's not managed by a mocking framework, it seems like there should be another term to describe this pattern. Any suggestions or ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload