Eclipse and "Maven"

User Generated

Fngryyvgr

Programming

Description

Hi, I need help with:

Follow a walkthrough for creating JUnit tests for the school application, following the JUnit framework of moving from the simple to the complex. You must follow the steps in your own integrated development environment (IDE) using the School Application zip file. You will submit a screenshot of the output of following along step-by-step with this tutorial.

Note: This software does not contain any bugs. The purpose of this assignment is for you to successfully create tests following the JUnit testing framework.


Unformatted Attachment Preview

CS 320 School Application Example Introduction During Module Three, you will learn about testing software using JUnit. JUnit is the industry standard for Java unit testing. It provides convenient methods that help developers test their code in different ways. JUnit supports true testing, false testing, and exception testing. Import the schoolApplication project 1. Select Import Maven Project. 2. Select Existing Maven Projects. 3. Import the project. Best practices      Test naming convention: Test(name of the class you are testing) Using a standard naming convention will make it easier to find and understand tests. Keep tests small and lightweight because unit tests should be run often (in some cases, every time someone checks in code). It is important to keep tests small and efficient. Test should be written in src/test directory. Create one test class per class. This is a general rule that supports object-oriented design. Test-driven development (TDD) simply means that you write your test cases first and then the code. 1. Below is a sample test for a Car object. The empty Car object has been created. However, there is currently no behavior in the class. In the next step, tests will be written to test setting the name in the car class. See example below. Note: Annotations are part of the JUnit framework. The example below uses @Before, which tells the framework to run this code before starting the test. @Test must be written above each test method to be included in the test execution. 2. After writing the tests that we want to pass, we go into the Car object and add the behavior so the tests pass. This is an example of TDD. 3. To run the test, right-click in the TestCar test and select Run As → JUnit Test. 4. Output: If the test passes, it will be green; if it fails, it will be red. JUnit provides a complete API for testing objects. 5. Next, we will write a test for setting the speed in the Car class. First, we will write the test as we did in the previous example, and next we will write the code for the test to pass. Below is an example of the Car class modified to make the TestCar test speed test point pass. 6. Next, we will run the test as we did before. See below for the output. From the JUnit console, we can see that two test cases were run and both passed. School Project Example The Module Three example will walk you through writing unit tests for a software project. You will start with the software features and end with writing JUnit tests. The features for the student application system (SAS) are below.  Features: The SAS will have the following features that must be tested to ensure the quality of the product: o Assign class to a student feature: The system shall allow the user to create a student and assign a class to a student. o Assign a grade from a class to a student: The system shall allow the user assign a grade for a student for an existing class and section. o Update a student’s grade per a class: The system shall allow the user update a student’s grade. The Module Three example project can be found in your Blackboard assignment, in the Assignment Guidelines and Rubric folder, or in the School Application zip file. To import the software project, review the instructions in the first section of this example. In order to provide testing coverage for the above features, we are going to apply the following testing strategy:  Test all model classes: It is important to start with the model classes because they are typically the smallest and least complex classes within the system. In addition, model classes typically do not have dependencies, and other complex classes like services often use many different types of models. For SAS, we will write tests for the Student object and the Class object. Right-click in the test directory and create a new JUnit test case. Name the test TestStudent. This will be the student object test. Every method in the Student class should be tested within this test. Model - Write TestStudent Below is the unit test for the student class. Because we want to test each method of the Student class, we have at least three tests. The @Before runs before the test is run. This is a good place to build objects that might be shared throughout the test. In this example, we created a Student object and populated the student with classes. Description of the Test The set name test point checks to make sure the student set name method is set correctly. The set ID test point checks to make sure the student ID is set correctly. The test CS101 class test point checks to make sure the setClass method is set correctly Model - Write TestClass Just as we did for the TestStudent test, we want to make sure we test every method in the Class object. This pattern should look familiar because we did took this same approach for test for the Student object. Description of the Test The set name test point checks to make sure the class set name method is set correctly. The set section test point checks to make sure the section set correctly. The set grade test point checks to make sure the grade is set correctly. Service - Write Student Service Test  Test all services: After creating unit tests for the models, we move on to the services. Services typically provide many different features and use many different objects. Sometimes it can be difficult to test a service without the use of mock objects. It is important that we test every method in the service. Again, we want to test every method in the StudentService class. Pay close attention to how you write your tests because JUnit has no consistent order in running the tests. For example, if we added the class for the student in the testAssignClass test, JUnit does not guarantee that test will run before the change grade test. Output From the output, we can tell that each of our tests passed for the school application.  Test the features: Next, we will move on to testing the features. Often there can be overlap with testing the features and services because services can provide all the features. However, it is important to understand that the features need to be explicitly tested against every data flow and corner case. Creating Test Suites JUnit test suites are used to organize unit tests and provide a rollup approach to executing tests. 1. To create a JUnit test suite, select the project, right-click, and select New → Other → JUnit Test Suite. 2. Next, enter the name of the test suite. In this example. we will create a model test suite named AllModelTests. 3. To add a JUnit test to the test suite, we need to include the name of the test suite’s annotation, @SuiteClasses. In this example, we added the model tests TestClass and TestStudent. 4. Next, run the test suite by right-clicking on the test suite and select Run as JUnit Test. In the figure below, you can see that each test point for the model class’s student and class have been tested. 5. Next, we will create an AllServiceTest test suite. Repeat the steps above for the service test suite. 6. Finally, we will another test suite named AllTests. This test suite will run the test suites described above from a single location. The benefits of using test suites is they can help organize tests and provide a simple test that will run all the unit tests for a project.
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Hello would you please check, i have one more day, for questions, clarification and any additional information , thank you in advance

Student Name:
Assignment:
Date of Submission

Project Testing Using Junit.
Application Name: School Application
Available Classes To Be Tested In School Application Class.
• Class
• Student
• StudentService

1. Class class.

2. TestClass

The TestClas test all methods in the class class to make sure all are correct. Same
behaviors have bee...


Anonymous
Excellent! Definitely coming back for more study materials.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags