This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Hi, I run netbeans 6.0 M2 from Ubuntu Dapper. The template that is generated for any class contains code like this: TestClass instance = null; instance.add(object); Which is wrong (nullpointerexception). So every testcase containing this must be altered. Is it possible to generate a statement like "TestClass instance = new TestClass(params...);" ?
Was not able to reproduce with 6.5 FCS. Please reopen and attach a sample, if it's yet the case for you.
AFAICS the error still occurs. I used version 6.5.1 and got the same results apart from some extra annotations. I will attach the project so you should be able to check the result. The following focuses on the issue. If I code the following class: public class TestClass { Date date; public TestClass(Date date) { this.date = date; } public boolean isLater(Date toDate) { return this.date.compareTo(toDate) > 0; } } The testcode generated for the isLaterDate() method looks like this: /** * Test of isLater method, of class TestClass. */ @Test public void testIsLater() { System.out.println("isLater"); Date toDate = null; TestClass instance = null; boolean expResult = false; boolean result = instance.isLater(toDate); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } Now, setting an instance to null and consequently calling it, will always result in an exception. So, this code will barf by definition. At the time I was just wondering whether the testcase could be generated in a more obliging way, like: public void testIsLater() { System.out.println("isLater"); Date toDate = new Date(); TestClass instance = new TestClass(new Date()); // You could also test new TestClass(null) boolean expResult = false; boolean result = instance.isLater(toDate); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } I realise this is not lifesaving code. I just feel that we should not have errors in the code we generate. Hope this helps.
Created attachment 79008 [details] A tarred gz file with test code (a netbeans 6.5.1 project)
Got the point. Thank you.