Hello, I am working on a project for my Intermediate programming class. I have the code and it works very well, but my professor wants us to use Junit testing to test our code. I've never used JUnit before, and have no idea how it works, and he provides little to no instructions/guidance on how to use it. Can someone please help me?
And on a side note, can anyone tell me if it is possible to have a boolean value (true or false) randomly set?
Here is the code I need to test:
package musicalinstruments; class MusicalInstrument { public String name; public boolean isPlaying; public boolean isTuned; public MusicalInstrument(){ isPlaying = false; isTuned = false; } public MusicalInstrument(String name){ this.name = name; } public void setName(String value){ name = value; } public String getName(){ return name; } public void play(){ isPlaying = true; } } class CWoodwind extends MusicalInstrument { private final String playSound; public CWoodwind(String name,String play){ super(name); playSound = play; } public void TestTune(){ System.out.println("" + super.getName() + " is playing out of tune"); isTuned = true; } public void TuneInstrument(){ if (isTuned == true){ System.out.println("" + super.getName() + " has been tuned."); isPlaying = true; } else{ System.out.println(""+ super.getName()+ " has not been tuned."); isPlaying = false; } } public void howToPlay(){ if (isPlaying == true){ System.out.println("" + super.getName() + " is playing using a " +playSound ); } else{ System.out.println(""+ super.getName() + " is not playing because it is not tuned."); isPlaying = false; } } public void unTune(){ if (isPlaying == true){ System.out.println("" + super.getName() + " is no longer in tune."); isTuned = false; } else{ } } public void StopPlay(){ if ( isPlaying == true){ System.out.println("" + super.getName() + " has stopped playing."); isPlaying = false; }else{} } } public class MusicalInstruments { //class Main { public static void main(String args[]){ CWoodwind wood = new CWoodwind("Woodwind","reed"); CBrass brass = new CBrass("Brass","mouth piece"); CString str = new CString("String","pluck and/or a bow"); CPercussion per = new CPercussion("Percussion","hitting"); wood.TestTune(); wood.TuneInstrument(); wood.howToPlay(); wood.unTune(); wood.StopPlay(); } }