Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please read all steps and also explain the answers I also posted the code photos and text version thank you Part1 1. On Bitbucket, fork

please read all steps and also explain the answers

I also posted the code photos and text version

thank you

Part1 1. On Bitbucket, fork the project CUS1156Fall2022Lab3. Then go to your git folder and clone it. Create project in Eclipse and link in the files from the git folder. 2. Take a look at Counter.java to see what it does. 3. You are going to create simple JUnit test class for this class. Right click on Counter, and choose New->JUnit Test Class. 4. In the dialog box, make sure that JUnit5 is selected. The default name of the class will be CounterTest, which is fine. Make sure that the setup() option is checked. Select the class you will be testing (Counter). 5. Click Next. On the next dialog box, choose the methods you want to test: increment and decrement. Click Finish. You might get a message about adding JUnit5 to the build path. Click OK. 6. What is the automatically generated code? Try running it and see what happens. 7. Now, fill in the methods. Use the CalculatorTest code as a model. The setup() method should create Counter object, and the testIncrement and testDecrement methods should test to see if the code works. Run the unit test. What do you see? How do you know if the tests worked or not? 8. Introduce an error into one of the methods and return the tests. Now what happens? How do you know there is an error? 9. Since your CounterTest.java is a new file, created in Eclipse, it is located in your Eclipse workspace, and Git doesn't know about it. So when you have finished your changes, copy the file from your Eclipse workspace to your lab3 project in your Git folder. Use this command to make Git aware of it (staging the file) git add CounterTest.java Check that it was added by using git status If the file is listed, you are ready to commit. 10. Commit your code and push to Bitbucket. Part2 11. Go back to Eclipse. Now take a look at Message.java and Mailbox.java. The Mailbox class manages a list of messages sent to a user. List and briefly

explain what each Mailbox method does (yes, you can look at the Javadoc comments) 12. Create JUnit test class for Message. Make sure the setup() option is checked. The methods you will be testing are getRecipient(), getSender, getText, and toString() - select those in the dialog box. 13. Run MessageTester. It should fail. 14. Now, add code to the setup() method. This code will look like this msgStr = "Test Message"; recip = "Frank"; sender ="Mary"; msg = new Message(sender, recip, msgStr); Also, add instance variables to MessageTester corresponding to the variables in the code above. 15. Now, fill in the code that tests getRecipient(). The method is testGetRecipient. The code should invoke the method getRecipient on the Message object created in setup() - the object name is msg. It should test the value returned by get Recipient to see if it is equal to the recipient stored in the instance variable recip. Describe how this test case works. 16. Fill in the code that tests getSender and getText. 17. Fill in the code that tests toString(). This is trickier because toString() returns a formatted string, and you need to write the test to check if it is the string you expect. The way to do is to create string named expectedResult, and assign to it the string you expect. Then, call toString() and test the result against the expectedResult. 18. Run your tester, and make sure it works. 19. Now, you are going to build a tester for the Mailbox class. Create the unit test class the same way as above. Make sure Setup is checked. 20. In the generated setup method, create instance of your mailbox. box = new Mailbox(owner); This will cause a fresh Mailbox object to be created before each test case. The Mailbox reference should be an instance variable of the test class. 21. Now, create tests for each of the Mailbox methods. For example, to test the isEmpty method, simply call isEmpty and test that it returns true, using assertTrue. public void testIsEmpty() {

assertTrue(box.isEmpty()); } This works because a newly created Mailbox is empty. You should also create test method that tests the return value of isEmpty when the Mailbox is NOT empty (add a message to the Mailbox and then test the return value of isEmpty). 22. To test getNextMessage, create message with known values, add it to the mailbox, then retrieve the next message by calling getNextMessage and test that the retrieved message has the same values as the one you added. You should also test that the retrieved message was removed from the mailbox. Q: If you add one message to an empty Mailbox and then retrieve it from the Mailbox, what method should you call to make sure the message was removed?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

Students also viewed these Programming questions

Question

The =now function takes no arguments * 1 point True False

Answered: 1 week ago