How do I go about creating a test class to test my methods in the code below. Everything I have found online about testing requires plugins or additional software. Although, probably not relevant , I am using Netbeans. I appreciate any help I can get. N
How do I go about creating a test class to test my methods in the code below.
I'm not sure what you are asking. A class is created by entering source code into a file and then compiling it.
If the purpose of the class is to test the methods of another class, the test class would create instances of the class using its constructors and then use those instances to call the classes methods. There would need to be special code in the test class to check the results of the calls to the methods to see if the methods preformed as desired.
There are lots of ways to test your classes. JUnit is used for something called unit testing.
Generally unit tests are in a different path than the program being tested, but still in the same package. That might seem confusing without an example. So say I have a program in
"workspace/MyApp" is your project directory. "src/main/java" is one convention for ordering Java files. "net/snortum/myapp" is the package and MyClass.java is the program to test. Your testing program might go in
Notice that it is in a different path, but in the same package.
Can someone provide me a real workplace example of how the files would be developed in a working environment. We can use my simple Account, Saving, Checking, Test Account as an example or any other simple example someone may have. So in the real world, would I create the parent and child classes in one .java file and then use a separate for testing or would I create a separate file for each.
I have uploaded a picture of my file tree in Netbeans so you can see where I currently have my two files stored.
R L Miller wrote:I apologize for posting such a rudimentary question but I have been, thus far, unsuccessful in my google searching.
There's NoNeedToSaySorry. This is exactly the place to post rudimentary questions.
Despite the fact that my parent class is declared public, my IDE throws me an error that my children are not public and cannot be accessed from outside of the file.
If you're talking about parent and child classes, are you extending them? (A more correct phrase would be super class and subclass.)
What is the full text of the error?
If nothing else it helps you to view them as entities in their own right.
It's also sort of what Java was designed around.