Re: Can't create test for class

2023-01-08 Thread Admin Netcrystals

  
  
  

	
	I also had strange problems with JUnit in Netbeans.I figured out t/ following…There seem to be multiple JUnit versions. In Netbeans I think you can choose between JUnit 3 and Junit 4 (or Junit 4 and Junit 5 I cant remember exactly). The older one, version Junit 3 has got very long and strange packages. The newer one, version Junit 4, relies on the org.junit package as far as I can remember.I think you can not mix them.Go to your Maven project, dependencies, remove the (most probably wrong) dependencies. Then rename your test folder in test-tmp. Compile your project without test. This is very important. Then add JUnit  dependencies to your pom (i take the new ones, JUnit 4 using org.junit package). Rename test-tmp back to test. Add imports to your test cases. Compile again.And dont mix the packages.This is how I solved this problem. From now on I only use org.junit package.Hope that helps.
	Gesendet von Outlook für iOS

  

 Von: Will Hartung Gesendet: Sonntag, Jänner 8, 2023 10:27 PMAn: Eric Bresie Cc: users Betreff: Re: Can't create test for class On Sun, Jan 8, 2023 at 7:25 AM Eric Bresie <ebre...@gmail.com> wrote:On Sat, Jan 7, 2023 at 9:07 PM Will Hartung <willhart...@gmail.com> wrote:I have  maven javafx project. Java 17, NB 15. It's also a modular application with a module-info.Might want to consider updating to NB 16...I believe some of the functionality around some of this has improved a little bit.I tried 16, and there was no change. I also tried simply closing the project and reloading it.  I try to create a test for a class, and all I get is an empty class. It has the JUnit imports, but no test methods. Just an empty class with an empty constructor. None of the methods.\Did you use  File..."New Unit Test"?  In this case then each test has to be manually added as desired.I was using the "Create Unit Test for Class" facility. Also, I can't seem to add any of my classes to the generated class. Auto complete doesn't see any of the classes, and when I compile the test, it also complains it can not find the classes.Have you tried any of the "hints" / "fixes" on the left gutter?  This often times when hovered over will help with some basic fixes.It simply says cannot find symbol. Maven projects tend to have additional "dependencies" listed in the Project explorer.  Dependencies can be added in this context or can be manually added in the pom.xml filesBe mindful it's important to have a good build of the dependency classes; if there is some kind of problem compiling one of them (i.e. say a missing dependency), then usage of that generated class may not work until such time as it's been successfully built and available for use elsewhere.The project (without the test) builds fine, the class I want the test for is within the project.  Yet, I created a simple JavaFX project, added a test to that, and it worked fine.I took my pom.xml from my project, and replaced the one from the simple project with it, and everything worked fine.So, I don't know what else I could check to see why the testing does not work for my project, but works for another with an identical pom file (barring the project name).Is the new project also a Maven project or was it originally an "Ant" project?  Netbeans treats these slightly differently and the project explorer shows different things (i.e. in "ant projects" right clicking allows configuring "Properties...Libraries''; with "maven projects" project shows "Dependencies [including a "Test Dependencies]" to be leverage (right clicking on the "Dependencies" here allows "Add Dependencies" which reflects it here and will modify the pom.xml file at the same time).It's a Maven project. Also, when trying to build, see if there are any clues in the Output pane that may help provide some additional guidance.Is just a simple syntax error:COMPILATION ERROR : -pkg/MyTest.java:[17,24] cannot find symbol  symbol:   class MyProjectClass  location: package pkg1 error-Eric Bresieebre...@gmail.com Thank Eric!Regards,WIll Hartung 


-
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Re: Can't create test for class

2023-01-08 Thread Will Hartung
On Sun, Jan 8, 2023 at 7:25 AM Eric Bresie  wrote:

>
>
>
> On Sat, Jan 7, 2023 at 9:07 PM Will Hartung  wrote:
>
>> I have  maven javafx project. Java 17, NB 15. It's also a modular
>> application with a module-info.
>>
>
> Might want to consider updating to NB 16...I believe some of the
> functionality around some of this has improved a little bit.
>

I tried 16, and there was no change. I also tried simply closing the
project and reloading it.


>
>
>> I try to create a test for a class, and all I get is an empty class. It
>> has the JUnit imports, but no test methods. Just an empty class with an
>> empty constructor. None of the methods.\
>>
>
> Did you use  File..."New Unit Test"?  In this case then each test has to
> be manually added as desired.
>

I was using the "Create Unit Test for Class" facility.


>
> Also, I can't seem to add any of my classes to the generated class. Auto
>> complete doesn't see any of the classes, and when I compile the test, it
>> also complains it can not find the classes.
>>
>
> Have you tried any of the "hints" / "fixes" on the left gutter?
> This often times when hovered over will help with some basic fixes.
>

It simply says cannot find symbol.


>
> Maven projects tend to have additional "dependencies" listed in the
> Project explorer.  Dependencies can be added in this context or can be
> manually added in the pom.xml files
>
> Be mindful it's important to have a good build of the dependency classes;
> if there is some kind of problem compiling one of them (i.e. say a missing
> dependency), then usage of that generated class may not work until such
> time as it's been successfully built and available for use elsewhere.
>

The project (without the test) builds fine, the class I want the test for
is within the project.


>
>
>> Yet, I created a simple JavaFX project, added a test to that, and it
>> worked fine.
>>
>> I took my pom.xml from my project, and replaced the one from the simple
>> project with it, and everything worked fine.
>>
>> So, I don't know what else I could check to see why the testing does not
>> work for my project, but works for another with an identical pom file
>> (barring the project name).
>>
>
> Is the new project also a Maven project or was it originally an "Ant"
> project?  Netbeans treats these slightly differently and the project
> explorer shows different things (i.e. in "ant projects" right clicking
> allows configuring "Properties...Libraries''; with "maven projects" project
> shows "Dependencies [including a "Test Dependencies]" to be leverage (right
> clicking on the "Dependencies" here allows "Add Dependencies" which
> reflects it here and will modify the pom.xml file at the same time).
>

It's a Maven project.


>
> Also, when trying to build, see if there are any clues in the Output pane
> that may help provide some additional guidance.
>

Is just a simple syntax error:
COMPILATION ERROR :
-
pkg/MyTest.java:[17,24] cannot find symbol
  symbol:   class MyProjectClass
  location: package pkg
1 error
-

Eric Bresie
> ebre...@gmail.com
>

Thank Eric!

Regards,

WIll Hartung


Re: Can't create test for class

2023-01-08 Thread Eric Bresie
On Sat, Jan 7, 2023 at 9:07 PM Will Hartung  wrote:

> I have  maven javafx project. Java 17, NB 15. It's also a modular
> application with a module-info.
>

Might want to consider updating to NB 16...I believe some of the
functionality around some of this has improved a little bit.


> I try to create a test for a class, and all I get is an empty class. It
> has the JUnit imports, but no test methods. Just an empty class with an
> empty constructor. None of the methods.\
>

Did you use  File..."New Unit Test"?  In this case then each test has to be
manually added as desired.

Using the Netbeans...Tools..Create/Update Tests on the project for the
class creating placeholder tests to provide a wealth of test coverage. This
method tends to generate a lot of test coverage (most with "fails"
initially to force review and updates of each test to make sure it's
written for the true need of the unit test case.)

Also, I can't seem to add any of my classes to the generated class. Auto
> complete doesn't see any of the classes, and when I compile the test, it
> also complains it can not find the classes.
>

Have you tried any of the "hints" / "fixes" on the left gutter?  This often
times when hovered over will help with some basic fixes.

Maven projects tend to have additional "dependencies" listed in the Project
explorer.  Dependencies can be added in this context or can be manually
added in the pom.xml files

Be mindful it's important to have a good build of the dependency classes;
if there is some kind of problem compiling one of them (i.e. say a missing
dependency), then usage of that generated class may not work until such
time as it's been successfully built and available for use elsewhere.


> Yet, I created a simple JavaFX project, added a test to that, and it
> worked fine.
>
> I took my pom.xml from my project, and replaced the one from the simple
> project with it, and everything worked fine.
>
> So, I don't know what else I could check to see why the testing does not
> work for my project, but works for another with an identical pom file
> (barring the project name).
>

Is the new project also a Maven project or was it originally an "Ant"
project?  Netbeans treats these slightly differently and the project
explorer shows different things (i.e. in "ant projects" right clicking
allows configuring "Properties...Libraries''; with "maven projects" project
shows "Dependencies [including a "Test Dependencies]" to be leverage (right
clicking on the "Dependencies" here allows "Add Dependencies" which
reflects it here and will modify the pom.xml file at the same time).

Also, when trying to build, see if there are any clues in the Output pane
that may help provide some additional guidance.

Eric Bresie
ebre...@gmail.com


Can't create test for class

2023-01-07 Thread Will Hartung
I have  maven javafx project. Java 17, NB 15. It's also a modular
application with a module-info.

I try to create a test for a class, and all I get is an empty class. It has
the JUnit imports, but no test methods. Just an empty class with an empty
constructor. None of the methods.

Also, I can't seem to add any of my classes to the generated class. Auto
complete doesn't see any of the classes, and when I compile the test, it
also complains it can not find the classes.

Yet, I created a simple JavaFX project, added a test to that, and it worked
fine.

I took my pom.xml from my project, and replaced the one from the simple
project with it, and everything worked fine.

So, I don't know what else I could check to see why the testing does not
work for my project, but works for another with an identical pom file
(barring the project name).

Thanks.

Regards,

Will Hartung