Re: Using Mockito with Netbeans

2024-03-01 Thread Ulrich Mayring
Brother, you're working for the wrong company. Adding fake/senseless 
tests decreases the quality of the software. As a developer you are not 
allowed to do that.


Testing the data layer against the database is the right thing to do 
here and you can do it in an integration test and also use JUnit for 
that. Then you can add the coverage produced by the integration tests to 
the coverage from the unit tests.


As for the database, if you have a containerized application then it is 
easy to just use the database container you have anyway. Alternatively 
you could fire up an in-process in-memory database like H2 and run your 
integration tests against that.


Ulrich

Am 29.02.24 um 22:43 schrieb Greenberg, Gary:

Yes, I do need to mock CRUD operations without accessing the database.
As I said, code was debugged and tested with the database, but to 
comply with the company policy
I do need to add these "fake" unit tests. I haven't used Mockito for 
about 10 years and don't want to spend much time
to refresh my knowledge. I do hope that NB have some mocking features 
that will help me.


*From:* Leo Donahue 
*Sent:* Thursday, February 29, 2024 1:29 PM
*Cc:* NetBeans Mailing List 
*Subject:* Re: Using Mockito with Netbeans

On Thu, Feb 29, 2024, 13:33 Greenberg,Gary  
wrote:


I already have all DTO and DAO classes written and debugged.
However, per company policy, unit test coverage must be no less than
75%.
Right now, I have it less than 30%, because this is database driven
project and to comply, I need to create
tests mocking database operations.


 >>mocking database operations

Do you mean that you need to mock CRUD in a unit test?

If you create mock data in the test, you control the mock data which 
means you're testing a hard coded value or testing for null and the 
database is never used.


Is that valuable?

Suppose you unit test pinging the database, as in select something and 
it fails because the database is down, or today no permissions were 
granted to your test account or your test user password expired... now 
what.  The unit test says something is broken but it may not be in your 
control.



*From:* Pieter van den Hombergh mailto:pieter.van.den.hombe...@gmail.com>>
*Sent:* Thursday, February 29, 2024 7:49 AM
*Cc:* NetBeans Mailing List mailto:users@netbeans.apache.org>>
*Subject:* Re: Using Mockito with Netbeans
generated tests from existing classes sounds like testing after the
fact.

Then I would consider generating the DAOs from information
available, like the database schema or the DTO classes which should
be of the record type.

but if you still insist, make the DAO tests inherit from a TestBase
class that configures the mocked data source.
If the DAO accepts the data source or a connection as dependency in
the injection sense, you are good to go and can verify the proper
use of the dependency by the DAO, which is the purpose of mocking.

I may find some time tomorrow to come up with a more elaborate answer.


Kind regards,
Pieter van den Hombergh.


met vriendelijke groet
Pieter van den Hombergh

Op do 29 feb 2024 01:40 schreef Greenberg, Gary
:

I am quite used to generate unit tests for my code using
Netbeans Tools->Create/Update Tests. JUnit is great.
However, now I need to create tests for some DAO classes where I
will need to mock database access.
I plan to use Mockito for that.  Does Netbeans have any features
automating Mockito test creation?

*Gary Greenberg*

Staff Software Engineer



--
iSYS Software GmbH

Ulrich Mayring | Full Stack Developer
Technology Lab / R

Tel: +49 (0) 89 46 23 28-0 | Fax  +49 (0) 89 46 23 28-14
email: ulrich.mayr...@isys.de

Grillparzerstraße 10 | D-81675 München
www.isys.de

Sitz der Gesellschaft: München | HRB 111760
Geschäftsführer: Stefan Fischer und Max Haller

-
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: Using Mockito with Netbeans

2024-02-29 Thread Vic Ricker
I can't help with Mockito, except to say that I use it with Netbeans all 
the time.  I write the tests mostly from scratch. I'm not sure what 
Netbeans could automate beyond creating template test methods as it does 
now.


One tip I can share, that I discovered by accident, is that Netbeans can 
show code coverage.  I think the option is hidden if you don't have 
coverage enabled.  We're using jacoco with maven. It will display a 
coverage report for the project and colorize your source files showing 
which lines are covered and not.


 Also, testcontainers is pretty cool for database integration testing.

On 2/29/24 19:56, Leo Donahue wrote:
https://plugins.netbeans.apache.org/?search=Mockito=21= 
<https://plugins.netbeans.apache.org/?search=Mockito=21=>


On Thu, Feb 29, 2024, 16:43 Greenberg, Gary  wrote:

Yes, I do need to mock CRUD operations without accessing the database.
As I said, code was debugged and tested with the database, but to
comply with the company policy
I do need to add these "fake" unit tests. I haven't used Mockito
for about 10 years and don't want to spend much time
to refresh my knowledge. I do hope that NB have some mocking
features that will help me.

*From:* Leo Donahue 
*Sent:* Thursday, February 29, 2024 1:29 PM
*Cc:* NetBeans Mailing List 
    *Subject:* Re: Using Mockito with Netbeans

On Thu, Feb 29, 2024, 13:33 Greenberg,Gary
 wrote:

I already have all DTO and DAO classes written and debugged.
However, per company policy, unit test coverage must be no
less than 75%.
Right now, I have it less than 30%, because this is database
driven project and to comply, I need to create
tests mocking database operations.


>>mocking database operations

Do you mean that you need to mock CRUD in a unit test?

If you create mock data in the test, you control the mock data
which means you're testing a hard coded value or testing for null
and the database is never used.

Is that valuable?

Suppose you unit test pinging the database, as in select something
and it fails because the database is down, or today no permissions
were granted to your test account or your test user password
expired... now what.  The unit test says something is broken but
it may not be in your control.


*From:* Pieter van den Hombergh

*Sent:* Thursday, February 29, 2024 7:49 AM
*Cc:* NetBeans Mailing List 
    *Subject:* Re: Using Mockito with Netbeans
generated tests from existing classes sounds like testing
after the fact.

Then I would consider generating the DAOs from information
available, like the database schema or the DTO classes which
should be of the record type.

but if you still insist, make the DAO tests inherit from a
TestBase class that configures the mocked data source.
If the DAO accepts the data source or a connection as
dependency in the injection sense, you are good to go and can
verify the proper use of the dependency by the DAO, which is
the purpose of mocking.

I may find some time tomorrow to come up with a more elaborate
answer.


Kind regards,
Pieter van den Hombergh.


met vriendelijke groet
Pieter van den Hombergh

Op do 29 feb 2024 01:40 schreef Greenberg, Gary
:

I am quite used to generate unit tests for my code using
Netbeans Tools->Create/Update Tests. JUnit is great.
However, now I need to create tests for some DAO classes
where I will need to mock database access.
I plan to use Mockito for that.  Does Netbeans have any
features automating Mockito test creation?

*Gary Greenberg*

Staff Software Engineer


Re: Using Mockito with Netbeans

2024-02-29 Thread Leo Donahue
https://plugins.netbeans.apache.org/?search=Mockito=21=

On Thu, Feb 29, 2024, 16:43 Greenberg, Gary  wrote:

> Yes, I do need to mock CRUD operations without accessing the database.
> As I said, code was debugged and tested with the database, but to
> comply with the company policy
> I do need to add these "fake" unit tests. I haven't used Mockito for about
> 10 years and don't want to spend much time
> to refresh my knowledge. I do hope that NB have some mocking features that
> will help me.
> --
> *From:* Leo Donahue 
> *Sent:* Thursday, February 29, 2024 1:29 PM
> *Cc:* NetBeans Mailing List 
> *Subject:* Re: Using Mockito with Netbeans
>
>
> On Thu, Feb 29, 2024, 13:33 Greenberg,Gary 
> wrote:
>
> I already have all DTO and DAO classes written and debugged.
> However, per company policy, unit test coverage must be no less than 75%.
> Right now, I have it less than 30%, because this is database driven
> project and to comply, I need to create
> tests mocking database operations.
>
>
> >>mocking database operations
>
> Do you mean that you need to mock CRUD in a unit test?
>
> If you create mock data in the test, you control the mock data which means
> you're testing a hard coded value or testing for null and the database is
> never used.
>
> Is that valuable?
>
> Suppose you unit test pinging the database, as in select something and it
> fails because the database is down, or today no permissions were granted to
> your test account or your test user password expired... now what.  The unit
> test says something is broken but it may not be in your control.
>
> --
> *From:* Pieter van den Hombergh 
> *Sent:* Thursday, February 29, 2024 7:49 AM
> *Cc:* NetBeans Mailing List 
> *Subject:* Re: Using Mockito with Netbeans
>
> generated tests from existing classes sounds like testing after the fact.
>
> Then I would consider generating the DAOs from information available, like
> the database schema or the DTO classes which should be of the record type.
>
> but if you still insist, make the DAO tests inherit from a TestBase class
> that configures the mocked data source.
> If the DAO accepts the data source or a connection as dependency in the
> injection sense, you are good to go and can verify the proper use of the
> dependency by the DAO, which is the purpose of mocking.
>
> I may find some time tomorrow to come up with a more elaborate answer.
>
>
> Kind regards,
> Pieter van den Hombergh.
>
>
> met vriendelijke groet
> Pieter van den Hombergh
>
> Op do 29 feb 2024 01:40 schreef Greenberg, Gary  >:
>
> I am quite used to generate unit tests for my code using Netbeans
> Tools->Create/Update Tests. JUnit is great.
> However, now I need to create tests for some DAO classes where I will need
> to mock database access.
> I plan to use Mockito for that.  Does Netbeans have any features
> automating Mockito test creation?
>
> *Gary Greenberg*
>
> Staff Software Engineer
>
>
>
>


Re: Using Mockito with Netbeans

2024-02-29 Thread Greenberg, Gary
Yes, I do need to mock CRUD operations without accessing the database.
As I said, code was debugged and tested with the database, but to comply with 
the company policy
I do need to add these "fake" unit tests. I haven't used Mockito for about 10 
years and don't want to spend much time
to refresh my knowledge. I do hope that NB have some mocking features that will 
help me.

From: Leo Donahue 
Sent: Thursday, February 29, 2024 1:29 PM
Cc: NetBeans Mailing List 
Subject: Re: Using Mockito with Netbeans


On Thu, Feb 29, 2024, 13:33 Greenberg,Gary  wrote:
I already have all DTO and DAO classes written and debugged.
However, per company policy, unit test coverage must be no less than 75%.
Right now, I have it less than 30%, because this is database driven project and 
to comply, I need to create
tests mocking database operations.

>>mocking database operations

Do you mean that you need to mock CRUD in a unit test?

If you create mock data in the test, you control the mock data which means 
you're testing a hard coded value or testing for null and the database is never 
used.

Is that valuable?

Suppose you unit test pinging the database, as in select something and it fails 
because the database is down, or today no permissions were granted to your test 
account or your test user password expired... now what.  The unit test says 
something is broken but it may not be in your control.


From: Pieter van den Hombergh 
mailto:pieter.van.den.hombe...@gmail.com>>
Sent: Thursday, February 29, 2024 7:49 AM
Cc: NetBeans Mailing List 
mailto:users@netbeans.apache.org>>
Subject: Re: Using Mockito with Netbeans

generated tests from existing classes sounds like testing after the fact.

Then I would consider generating the DAOs from information available, like the 
database schema or the DTO classes which should be of the record type.

but if you still insist, make the DAO tests inherit from a TestBase class that 
configures the mocked data source.
If the DAO accepts the data source or a connection as dependency in the 
injection sense, you are good to go and can verify the proper use of the 
dependency by the DAO, which is the purpose of mocking.

I may find some time tomorrow to come up with a more elaborate answer.


Kind regards,
Pieter van den Hombergh.


met vriendelijke groet
Pieter van den Hombergh

Op do 29 feb 2024 01:40 schreef Greenberg, Gary :
I am quite used to generate unit tests for my code using Netbeans 
Tools->Create/Update Tests. JUnit is great.
However, now I need to create tests for some DAO classes where I will need to 
mock database access.
I plan to use Mockito for that.  Does Netbeans have any features automating 
Mockito test creation?


Gary Greenberg

Staff Software Engineer




Re: Using Mockito with Netbeans

2024-02-29 Thread Leo Donahue
On Thu, Feb 29, 2024, 13:33 Greenberg,Gary 
wrote:

> I already have all DTO and DAO classes written and debugged.
> However, per company policy, unit test coverage must be no less than 75%.
> Right now, I have it less than 30%, because this is database driven
> project and to comply, I need to create
> tests mocking database operations.
>

>>mocking database operations

Do you mean that you need to mock CRUD in a unit test?

If you create mock data in the test, you control the mock data which means
you're testing a hard coded value or testing for null and the database is
never used.

Is that valuable?

Suppose you unit test pinging the database, as in select something and it
fails because the database is down, or today no permissions were granted to
your test account or your test user password expired... now what.  The unit
test says something is broken but it may not be in your control.

--
> *From:* Pieter van den Hombergh 
> *Sent:* Thursday, February 29, 2024 7:49 AM
> *Cc:* NetBeans Mailing List 
> *Subject:* Re: Using Mockito with Netbeans
>
> generated tests from existing classes sounds like testing after the fact.
>
> Then I would consider generating the DAOs from information available, like
> the database schema or the DTO classes which should be of the record type.
>
> but if you still insist, make the DAO tests inherit from a TestBase class
> that configures the mocked data source.
> If the DAO accepts the data source or a connection as dependency in the
> injection sense, you are good to go and can verify the proper use of the
> dependency by the DAO, which is the purpose of mocking.
>
> I may find some time tomorrow to come up with a more elaborate answer.
>
>
> Kind regards,
> Pieter van den Hombergh.
>
>
> met vriendelijke groet
> Pieter van den Hombergh
>
> Op do 29 feb 2024 01:40 schreef Greenberg, Gary  >:
>
> I am quite used to generate unit tests for my code using Netbeans
> Tools->Create/Update Tests. JUnit is great.
> However, now I need to create tests for some DAO classes where I will need
> to mock database access.
> I plan to use Mockito for that.  Does Netbeans have any features
> automating Mockito test creation?
>
> *Gary Greenberg*
>
> Staff Software Engineer
>
>
>
>


Re: Using Mockito with Netbeans

2024-02-29 Thread Greenberg, Gary
I already have all DTO and DAO classes written and debugged.
However, per company policy, unit test coverage must be no less than 75%.
Right now, I have it less than 30%, because this is database driven project and 
to comply, I need to create
tests mocking database operations.

From: Pieter van den Hombergh 
Sent: Thursday, February 29, 2024 7:49 AM
Cc: NetBeans Mailing List 
Subject: Re: Using Mockito with Netbeans

generated tests from existing classes sounds like testing after the fact.

Then I would consider generating the DAOs from information available, like the 
database schema or the DTO classes which should be of the record type.

but if you still insist, make the DAO tests inherit from a TestBase class that 
configures the mocked data source.
If the DAO accepts the data source or a connection as dependency in the 
injection sense, you are good to go and can verify the proper use of the 
dependency by the DAO, which is the purpose of mocking.

I may find some time tomorrow to come up with a more elaborate answer.


Kind regards,
Pieter van den Hombergh.


met vriendelijke groet
Pieter van den Hombergh

Op do 29 feb 2024 01:40 schreef Greenberg, Gary :
I am quite used to generate unit tests for my code using Netbeans 
Tools->Create/Update Tests. JUnit is great.
However, now I need to create tests for some DAO classes where I will need to 
mock database access.
I plan to use Mockito for that.  Does Netbeans have any features automating 
Mockito test creation?


Gary Greenberg

Staff Software Engineer




Re: Using Mockito with Netbeans

2024-02-29 Thread Pieter van den Hombergh
generated tests from existing classes sounds like testing after the fact.

Then I would consider generating the DAOs from information available, like
the database schema or the DTO classes which should be of the record type.

but if you still insist, make the DAO tests inherit from a TestBase class
that configures the mocked data source.
If the DAO accepts the data source or a connection as dependency in the
injection sense, you are good to go and can verify the proper use of the
dependency by the DAO, which is the purpose of mocking.

I may find some time tomorrow to come up with a more elaborate answer.


Kind regards,
Pieter van den Hombergh.


met vriendelijke groet
Pieter van den Hombergh

Op do 29 feb 2024 01:40 schreef Greenberg, Gary :

> I am quite used to generate unit tests for my code using Netbeans
> Tools->Create/Update Tests. JUnit is great.
> However, now I need to create tests for some DAO classes where I will need
> to mock database access.
> I plan to use Mockito for that.  Does Netbeans have any features
> automating Mockito test creation?
>
> *Gary Greenberg*
>
> Staff Software Engineer
>
>
>


Using Mockito with Netbeans

2024-02-28 Thread Greenberg, Gary
I am quite used to generate unit tests for my code using Netbeans 
Tools->Create/Update Tests. JUnit is great.
However, now I need to create tests for some DAO classes where I will need to 
mock database access.
I plan to use Mockito for that.  Does Netbeans have any features automating 
Mockito test creation?


Gary Greenberg

Staff Software Engineer