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.
Netbeans really makes working with Maven a pleasure. As a TDD person, I always create my test first and reference a class that I am going to test (it does not exist yet). Inside my Test, I get a can't find symbol, and I get prompted 'Create class xxx' in package yyy When creating this class it creates a class in src/test/java' which is usually not what I want. Can I suggest there should be two options when this this is prompted in a unit test 'Create class xxx' in main package yyy 'Create class xxx' in test package yyy If there is a short cut key for these it would be beautiful. Search dependency can still be the top one.
While this sounds like a valid thing to do it's not usually how I would approach TDD. Instead, first create your interface contract in your projects `src/main/java`, then a concrete implementation where all methods throw `throw new UnsupportedOperationException("Not supported yet.");`. Then choose Tools > Create/Update Tests... This way your junit/testNG stubs get nutted out for you so you don't need to do the work hitting the hint to create the method for every single test you're about to create. In TDD you're testing the contracts, not the structure of the implementation. Here's the outlined steps. 1. Create new interface contract. 2. Create new implementation extending interface in #1. 3. Use the hint "Implement all abstract methods" 4. Choose Tools > Create/Update Tests... This is only 4 steps and gives you failing tests for all contracts. If you choose to test private members or parts of the implementation not part of the contract then that can be achieved by repeatedly invoking "Create/Update Tests...".
Thanks @BrettRyan. I may be taking Uncle Bob's 'The Three Rules Of Tdd' a little our of context, but I don't think so. Uncle Bob shows how to create the test first, and then the implementation. http://butunclebob.com/files/downloads/Bowling%20Game%20Kata.ppt Also here is a YouTube video where is seems IntelliJ always defaults to creating new classes in src/main/java (I think it's bad to do something just because a competitor does it, but in this case I think it's a good idea.) https://www.youtube.com/watch?v=NDikuKeYATg
Created attachment 152344 [details] Proposed patch Here is a patch proposal. Please review. The patch introduces a check. If the current file in a test source group two fixes are shown (one for src and one for src-test). If the current file in a main source group one fixe is shown (one for src).
Created attachment 152345 [details] Patch in action
Created attachment 152346 [details] Patch in action v2
Looks wonderful, thanks @Markiewb ! If the order could be 'create in package src/test/java' and then 'create in package src/main/java' please.
Created attachment 152358 [details] Proposed patch v2 (with reordering of hints) (In reply to rjdkolb from comment #6) > If the order could be 'create in package src/test/java' and then 'create in > package src/main/java' please. Fixed in the new patch. The patch implements EnhancedFix instead of Fix to provide #getSortText() See related following issue, where the same approach has been used. https://netbeans.org/bugzilla/show_bug.cgi?id=231133
Created attachment 152359 [details] Patch in action v3
Excellent, thanks Markiewb
Just a question: what is the reason the SourceGroup displayName (i.e. "Source Packages" is not used, "Unit Test Packages" and display relative root path instead ? Does it seem more readable / illustrative ?
(In reply to Svata Dedic from comment #10) > Just a question: what is the reason the SourceGroup displayName (i.e. > "Source Packages" is not used, "Unit Test Packages" and display relative > root path instead ? > > Does it seem more readable / illustrative ? @Svata: You can change it as you like! It is only my preference, but I am also fine if texts like "Source Packages" are used.
I've changed the code a little; I would preferer not to use relative paths to project, as freeform ant project may include source roots unrelated to the project directory. I also filed issue #252136 against project system - I was not able to enumerate multiple test source roots (or maybe I overlooked some similar approach). Patch applied as jet-main#88989df5c99a. Thanks for the contribution!
Thanks Svata and @Markiewb!
Integrated into 'main-silver', will be available in build *201505120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/88989df5c99a User: Svata Dedic <sdedic@netbeans.org> Log: #250809: implemented create class in test packages (by Markiewb)