views:

45

answers:

2

I am new to java and to netbeans so my apologies if this is a simple question.

I made a 'Java Class Library' Project in Netbeans 6.9.1

I added a few classes to it and hit 'Build'. It builds with no errors. However the problem is I know there are errors.

It seems as though I can make up class names and hit build and it doesnt provide me with any feedback.

How can I make it so that netbeans validates my code when buildling a class library?

I am unable to 'run' the project becuase there is no Main. However this is a class library and I dont want to make test applications in my library.

Edit: For example I can write the following and a 'clean & build' still works

MadeUpName x = new MadeUpName();

This will build even though I have no class or reference to a class that contains

MadeUpName

I also have no 'Import' statments as of yet and it still builds.... Thanks, stephanie

+1  A: 

1) To test a Java Class Library project you should create another project and add your "Java Class Library" project as project dependency. In this new testing project you can write class with main method to test features of the class library. When you will build the test project NetBeans IDE will also build the class library project and will add the JAR file in the class path of the testing project.

2) If the Java Class Library projects compiles through "Clean & Build" that means the project has no syntax errors. That means your code may have logical errors which are not detected by the Java compiler. Usually class library developers create JUnit test cases to find out logical errors, and you are also strongly advised to use JUnit tests for your project.

with regards
Tushar Joshi, Nagpur

Tushar Joshi
What i dont understand is I have declarations such as 'FakeClass a = new FakeClass();' and it lets me build even though 'FakeClass' doesnt exist. Its like its not checking anything...
Without Me It Just Aweso
+1  A: 

Ideally you should test a class library by writing unit tests (rather than test applications) that exercise the classes in your library. There are several unit-testing frameworks available that can help you write the unit tests. The most popular is JUnit.

The test cases should be placed in a different source folder in the same project as the code they are testing. When you build the project you should ensure that the test classes are not included in the JAR file. If you use a build tool like Maven it will do this for you as long as you follow it's project conventions.

Update

Based on your comments, and the fact that you tagged your question with Groovy, I'm guessing that the library is written in Groovy? Your problem seems to be that Netbeans doesn't perform the kind of type-checking that you get with Java (or other statically-typed languages)?

Because Groovy is a dynamic language, it's not possible for the compiler to perform the same rigorous type-checking that you get with Java, but at the very least the Netbeans Groovy editor should provide some hints/warnings if you're referencing classes that don't exist (for example). Are you sure you're opening the code in the correct editor (you may need to install a Groovy plugin first).

You should use GroovyTestCase, rather than JUnit directly to test a Groovy library.

Don
I do intend to write unit tests to verify functionality but the problem is right now I cant get netbeans to verify syntax.
Without Me It Just Aweso
Hello, Yes the class library is written in groovy. I tried to start writing JUnit tests but making groovytests opens up a wholenother bag of worms.... blah
Without Me It Just Aweso