课程: Complete Guide To Java Testing with JUnit 5 & Mockito
Using test cases to verify software
课程: Complete Guide To Java Testing with JUnit 5 & Mockito
Using test cases to verify software
- [Instructor] One key element in the testing process are test cases. They're essentially detailed documentation that outlines specific conditions and steps to be followed to verify whether a particular aspect of the software works correctly. Each test case consists of inputs, execution conditions, expected outcomes, and often, actual outcomes. These elements collectively guide testers through the process of evaluating the software's behavior under various scenarios. Let's take a look at some test case examples for a hypothetical e-commerce website. One component we'll want to test is whether the user registration works as expected. Most tests require some setup and execution of the code and some verification to ensure the code works as expected. Here, the setup includes navigating to the Registration page and setting up the details for the user we want to register. To execute the code we want to test, we would click the Register button. Then we'd want to verify that the user was actually registered. To do this, we'd log in with the newly registered credentials. With the well-defined expected outcome, we can verify whether the actual outcome matches the expectation. Another component we might want to test is product pricing. We want to ensure that the product price is reflected appropriately when the product is discounted. This type of test case would also require some data setup, including a sample product with a sample discount. To run the test, we'd call the pricing function with the test data and calculate the correct price. Then we'd verify the functionality works as expected, checking the expected price matches the actual price. With this test case, our scope is a little smaller in that we're only verifying a single function rather than an overall registration flow. Let's try one more test case. Consider verifying Add to Cart functionality. We'd set up test cart data for the user's cart and for the product we want to add. To see if the functionality works, we'd execute the Add to Cart method and verify that the user's cart has one more item along with the corresponding new cart total. This test case is a little different because we verify two things instead of one. We could also increase the scope of the test by verifying the users logged in, given that's a requirement to create a cart. Now each feature within an application should have some type of testing that ensures it works as expected and meets the user's needs. That testing will typically include test cases that cover the happy path, as well as any edge cases, including error cases. The happy path refers to the scenario where everything goes as expected without encountering any or exceptions. The test cases we've covered in this video test the happy path scenario. They represent the ideal flow through the system , where inputs are valid, processes are executed successfully, and expected outcomes are achieved. With our Add to Cart example, we'd also want to test the error scenarios, such as when access to the database isn't working. We'll need to define what the expected outcome is in that scenario, and then ensure our software has that expected behavior. It should gracefully respond to errors, displaying the appropriate error messages and keeping the application stable. Now, you could write test cases for every possible situation that could occur in your application, but typically, testing one happy path scenario and every type of error scenario will be enough to ensure high software quality. You want to be aware of how your program will behave when things go as expected, as well as when they do not.
内容
-
-
-
Key concepts in software testing2 分钟 39 秒
-
Using test cases to verify software4 分钟 1 秒
-
(已锁定)
Types of software testing5 分钟 4 秒
-
(已锁定)
Automated vs. manual testing3 分钟
-
(已锁定)
What is a testing framework?1 分钟 38 秒
-
(已锁定)
Java testing frameworks2 分钟 48 秒
-
(已锁定)
Understand test-driven development (TDD)3 分钟 43 秒
-
(已锁定)
Ensure quality with test coverage1 分钟 33 秒
-
(已锁定)
Write effective tests with F.I.R.S.T. testing principles3 分钟 23 秒
-
-
-
-
-
-
-
-
-