Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.5.6, 1.7.0
-
Fix Version/s: 1.8.x
-
Component/s: None
-
Labels:None
-
Environment:Windows XP, Eclipse Ganymede, Groovy Eclipse plugin using Groovy 1.5.6
-
Number of attachments :
Description
Here's an example of a simple test, in which the return type of a Private Static Method within a Class is needed to return a String different from what it would normally return:
void testCheckSunrise(){
WeatherMonitor.metaClass.static.findSunriseTime = {-> '5:57 AM'}
WeatherMonitor testSubject = new WeatherMonitor()
assertEquals('5:57 AM', testSubject.sunrise)
}
And here is the Class itself:
public class WeatherMonitor { def getSunrise(){ findSunriseTime() } private static findSunriseTime(){ '7:15 AM' } }
The result of the test execution is always '7:15 AM' and so the test will always fail. This would be a great help in Unit Testing techniques, especially Test Driven Development in Groovy.
It would be great to see Groovy have this capability.
Activity
Paul King
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
Here's an example of a simple test, in which the return type of a Private Static Method within a Class is needed to return a String different from what it would normally return: void testCheckSunrise(){ WeatherMonitor.metaClass.'static'.findSunriseTime = {-> '5:57 AM'} WeatherMonitor testSubject = new WeatherMonitor() assertEquals('5:57 AM', testSubject.getSunrise()) } And here is the Class itself: public class WeatherMonitor{ def getSunrise(){ findSunriseTime() } private static findSunriseTime(){ '7:15 AM' } } The result of the test execution is always '7:15 AM' and so the test will always fail. This would be a great help in Unit Testing techniques, especially Test Driven Development in Groovy. It would be great to see Groovy have this capability. |
Here's an example of a simple test, in which the return type of a Private Static Method within a Class is needed to return a String different from what it would normally return: {code} void testCheckSunrise(){ WeatherMonitor.metaClass.'static'.findSunriseTime = {-> '5:57 AM'} WeatherMonitor testSubject = new WeatherMonitor() assertEquals('5:57 AM', testSubject.sunrise) } {code} And here is the Class itself: {code} public class WeatherMonitor { def getSunrise(){ findSunriseTime() } private static findSunriseTime(){ '7:15 AM' } } {code} The result of the test execution is always '7:15 AM' and so the test will always fail. This would be a great help in Unit Testing techniques, especially Test Driven Development in Groovy. It would be great to see Groovy have this capability. |
Paul King
made changes -
| Description |
Here's an example of a simple test, in which the return type of a Private Static Method within a Class is needed to return a String different from what it would normally return: {code} void testCheckSunrise(){ WeatherMonitor.metaClass.'static'.findSunriseTime = {-> '5:57 AM'} WeatherMonitor testSubject = new WeatherMonitor() assertEquals('5:57 AM', testSubject.sunrise) } {code} And here is the Class itself: {code} public class WeatherMonitor { def getSunrise(){ findSunriseTime() } private static findSunriseTime(){ '7:15 AM' } } {code} The result of the test execution is always '7:15 AM' and so the test will always fail. This would be a great help in Unit Testing techniques, especially Test Driven Development in Groovy. It would be great to see Groovy have this capability. |
Here's an example of a simple test, in which the return type of a Private Static Method within a Class is needed to return a String different from what it would normally return: {code} void testCheckSunrise(){ WeatherMonitor.metaClass.static.findSunriseTime = {-> '5:57 AM'} WeatherMonitor testSubject = new WeatherMonitor() assertEquals('5:57 AM', testSubject.sunrise) } {code} And here is the Class itself: {code} public class WeatherMonitor { def getSunrise(){ findSunriseTime() } private static findSunriseTime(){ '7:15 AM' } } {code} The result of the test execution is always '7:15 AM' and so the test will always fail. This would be a great help in Unit Testing techniques, especially Test Driven Development in Groovy. It would be great to see Groovy have this capability. |
blackdrag blackdrag
made changes -
| Component/s | mocks and stubs [ 13113 ] | |
| Fix Version/s | 1.8-beta-x [ 15750 ] | |
| Issue Type | Test [ 6 ] | Bug [ 1 ] |
| Affects Version/s | 1.7.0 [ 14665 ] | |
| Summary | Cannot override private static method with Groovy's MetaClass | Cannot override private static method using EMC |
add code tags