Skip to main content
added 186 characters in body
Source Link
Rui
  • 1.9k
  • 2
  • 16
  • 22

This section from the book Clean Code, in Chapter 10 Classes > Class Organization > Encapsulation kinda implies that testing on private method is a pseudo-proposition.

We like to keep our variables and utility functions private, but we're not fanatic about it. Sometimes we need to make a variable or utility functions protected so that it can be accessed by a test. For us, tests rule. If a test in the same package needs to call a function or access a variable, we'll make it protected or package scope. However, we'll first look for a way to maintain privacy. Loosening encapsulation is always the last resort.

IMHO private method is just a wrapper of a partial responsibility implementation, which is invoked in non-private method. So if testing on a private method is very important, the access scope should be enlarged so that a unit test framework like JUnit is able to run test on it. Otherwise, the only way to "test" private method is in fact the test on a non-private method, which calls that private method

Moreover, the Deencapsultion class of JMockit was removed last year. This kinda proved that "test on private method" is a pseudo-proposition

This section from the book Clean Code, in Chapter 10 Classes > Class Organization > Encapsulation kinda implies that testing on private method is a pseudo-proposition.

We like to keep our variables and utility functions private, but we're not fanatic about it. Sometimes we need to make a variable or utility functions protected so that it can be accessed by a test. For us, tests rule. If a test in the same package needs to call a function or access a variable, we'll make it protected or package scope. However, we'll first look for a way to maintain privacy. Loosening encapsulation is always the last resort.

IMHO private method is just a wrapper of a partial responsibility implementation, which is invoked in non-private method. So if testing on a private method is very important, the access scope should be enlarged so that a unit test framework like JUnit is able to run test on it. Otherwise, the only way to "test" private method is in fact the test on a non-private method, which calls that private method

This section from the book Clean Code, in Chapter 10 Classes > Class Organization > Encapsulation kinda implies that testing on private method is a pseudo-proposition.

We like to keep our variables and utility functions private, but we're not fanatic about it. Sometimes we need to make a variable or utility functions protected so that it can be accessed by a test. For us, tests rule. If a test in the same package needs to call a function or access a variable, we'll make it protected or package scope. However, we'll first look for a way to maintain privacy. Loosening encapsulation is always the last resort.

IMHO private method is just a wrapper of a partial responsibility implementation, which is invoked in non-private method. So if testing on a private method is very important, the access scope should be enlarged so that a unit test framework like JUnit is able to run test on it. Otherwise, the only way to "test" private method is in fact the test on a non-private method, which calls that private method

Moreover, the Deencapsultion class of JMockit was removed last year. This kinda proved that "test on private method" is a pseudo-proposition

Source Link
Rui
  • 1.9k
  • 2
  • 16
  • 22

This section from the book Clean Code, in Chapter 10 Classes > Class Organization > Encapsulation kinda implies that testing on private method is a pseudo-proposition.

We like to keep our variables and utility functions private, but we're not fanatic about it. Sometimes we need to make a variable or utility functions protected so that it can be accessed by a test. For us, tests rule. If a test in the same package needs to call a function or access a variable, we'll make it protected or package scope. However, we'll first look for a way to maintain privacy. Loosening encapsulation is always the last resort.

IMHO private method is just a wrapper of a partial responsibility implementation, which is invoked in non-private method. So if testing on a private method is very important, the access scope should be enlarged so that a unit test framework like JUnit is able to run test on it. Otherwise, the only way to "test" private method is in fact the test on a non-private method, which calls that private method