You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by Eric Bresie <eb...@gmail.com> on 2022/03/05 16:22:49 UTC

Setting Up a File for Use Unit Tests

While writing unit tests for my python development (modeled on existing
unit code in the nbpython codebase) to test "execution of a script", I'm
having problems injecting the "test.py" code and was hoping someone could
provide some guidance on standardize unit test setup in Netbeans IDE/Module
development.

The previous tests looks for some file in a "target/data" folder which in
my new codebase is not created in any way.

So what is the proper way to deal with unit test resources to include
(1) generate a "test file" in a standardized way (i.e. store in above
mentioned "target/data" folder)
(2) reference another file (i.e. a template file associated within the
code, reference a "test resource", etc.)?

I have a "template.py" currently used in "new file creation" which maybe
could be used and have added a "test resource" hello.py code but not sure
if there is a standardized way of using either of these in Netbeans unit
testing.

Eric Bresie
ebresie@gmail.com

Re: Setting Up a File for Use Unit Tests

Posted by Eric Bresie <eb...@gmail.com>.
For reference, I started looking here
https://netbeans.apache.org/kb/docs/java/junit-intro.html (found here
https://github.com/apache/netbeans-website/blob/master/netbeans.apache.org/src/content/kb/docs/java/junit-intro.asciidoc
) provides some junit intro but didn't provide any information on file
usages in a test.  May be worth updating this page as it seems a little
dated (i.e. it focused on JUnit 3 and 4).   Any Unit Test experts up for
that task?  Of note, the link on the doc page mentions raising a "JIRA"
ticket which currently takes to a recent issue indicating no longer using
JIRA which is fine but since this is documentation, assume it would be
better to raise an issue in the netbeans-website context which does not
support "Issues" yet.  Does the netbeans-website page need to have this
enabled as well?  And do the "links" on each document page need to be
adjusted to account for changes from JIRA to github issues?

On Sat, Mar 5, 2022 at 10:16 PM Jaroslav Tulach <ja...@gmail.com>
wrote:

> Dne sobota 5. března 2022 17:22:49 CET, Eric Bresie napsal(a):
> > While writing unit tests for my python development (modeled on existing
> > unit code in the nbpython codebase) to test "execution of a script", I'm
> > having problems injecting the "test.py" code and was hoping someone could
> > provide some guidance on standardize unit test setup in Netbeans
> IDE/Module
> > development.
> >
> > The previous tests looks for some file in a "target/data" folder which in
> > my new codebase is not created in any way.
>
> Using [NbTestCase.getDataDir()](https://github.com/apache/netbeans/blob/
> master/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java#L1223
> <https://github.com/apache/netbeans/blob/master/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java#L1223>
> ).
>

I  looked there and had follow up questions:

   1. There is a comment indicating: // XXX should this be deprecated? Was
   there a plan to change this portion in some way and replace it with
   something else?
   2. It mentions "String xtestData = System.getProperty("xtest.data");"
   Any  details on usage of "xtest.data" is here?  Is this a common
   "xUnitTest" type test frameworks property (i.e. a convention usable in more
   than just JUnit) for associating a "data" folder?   Are there any good
   examples of this in use?
   3. So as part of test setup or during build, is the expectation to
   create a "data'' folder somewhere during build time (i.e. maybe in
   "target/data ' context) and then copy the file into it?  Any examples of
   this available (i.e. setting up tests or builds)?

> So what is the proper way to deal with unit test resources to include
> > (1) generate a "test file" in a standardized way (i.e. store in above
> > mentioned "target/data" folder)
> > (2) reference another file (i.e. a template file associated within the
> > code, reference a "test resource", etc.)?
>
> I tend to use `Class.getResource("my.py")` and copy it into a temporary
> directory.
>

Does this end up looking  in the test/resources/my.py folder/file or will
it look in my src/resources folders?  Or both (i.e. based on classpath)?


> -jt
>
> > I have a "template.py" currently used in "new file creation" which maybe
> > could be used and have added a "test resource" hello.py code but not sure
> > if there is a standardized way of using either of these in Netbeans unit
> > testing.
>

So would getResource("template.py") from this be better or a completely
different new test script be helpful here?

In the github automated build context, is anyone aware of how to have a
"python executable" instance installed for use during testing?

I'm trying to also add some "Install Python" type functionality similar to
the Java install functionality so any guidance there is appreciated as well.

Re: Setting Up a File for Use Unit Tests

Posted by Jaroslav Tulach <ja...@gmail.com>.
Dne sobota 5. března 2022 17:22:49 CET, Eric Bresie napsal(a):
> While writing unit tests for my python development (modeled on existing
> unit code in the nbpython codebase) to test "execution of a script", I'm
> having problems injecting the "test.py" code and was hoping someone could
> provide some guidance on standardize unit test setup in Netbeans IDE/Module
> development.
> 
> The previous tests looks for some file in a "target/data" folder which in
> my new codebase is not created in any way.

Using [NbTestCase.getDataDir()](https://github.com/apache/netbeans/blob/
master/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java#L1223).

> So what is the proper way to deal with unit test resources to include
> (1) generate a "test file" in a standardized way (i.e. store in above
> mentioned "target/data" folder)
> (2) reference another file (i.e. a template file associated within the
> code, reference a "test resource", etc.)?

I tend to use `Class.getResource("my.py")` and copy it into a temporary 
directory.

-jt

> I have a "template.py" currently used in "new file creation" which maybe
> could be used and have added a "test resource" hello.py code but not sure
> if there is a standardized way of using either of these in Netbeans unit
> testing.
> 
> Eric Bresie
> ebresie@gmail.com





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org

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