Author Archives: Tianyuan Wang

Learn how to write unit tests

Hello everyone,

Today I want share a tutorial which explains unit testing with the JUnit 5 framework (JUnit Jupiter). It explains the creation of JUnit 5 tests with the Maven and Gradle build system. After reading it, you will definitely gain something new.

Here is the link:

https://www.vogella.com/tutorials/JUnit/article.html

“JUnit 5 tutorial – Learn how to write unit tests”

By Vogella GmbH

As a new software testing student, I recently stumbled upon the JUnit tutorial on the Vogella website while browsing for some knowledge about software testing. In this blog post, I will share my insights and discuss how this can help This knowledge is applied to our development practices.

This tutorial can be said to be a comprehensive guide that covers various details of JUnit. Including “What is software testing”, “Using Maven in the Eclipse IDE”, “Using the Eclipse IDE for creating and running JUnit test”, “JUnit 5 extensions” and so on. In chapters 1.2 and 1.3 of the article, it demonstrates how to use “assert” to check expected and actual results. Because “assert” is a powerful function, it contains almost all the judgments required by the scenario, so being proficient in the “assert” function is necessary as a software tester. Also, in Chapter 1.5 and 1.6, the article talks about unit tests are created in a separate source folder to keep the test code separate from the real code. This is the problem I started to encounter in HW1, my Gitpod cannot idenify all my Junit5 command. Because my test code and the real code are in the same path. So we should have a main path and a test path, as follows:

src/main/java – for Java classes

src/test/java – for test classes

In Chapter 2 of the article it explains how to use Assertions and assumptions. There are also examples of Testing for exceptions and Testing multiple assertions (grouped assertions) with assertAll, which we need to be proficient in and will use in the following assignments.

import static org.junit.jupiter.api.Assertions.assertThrows;

@Test void exceptionTesting() {

// set up user

Throwable exception = assertThrows(IllegalArgumentException.class, () -> user.setAge(“23”));

assertEquals(“Age must be an Integer.”, exception.getMessage());

}

Anyway, that’s why I recommend this tutorial. As a student who has just started learning software testing, I not only need theoretical knowledge about JUnit, I also need examples and explanations of practical application of this knowledge. This tutorial is exactly what we need, high quality and easy to understand. It left a lasting impression on me and I hope everyone will learn something from this tutorial.

From the blog CS@Worcester – Ty-Blog by Tianyuan Wang and used with permission of the author. All other rights reserved by the author.

Video suitable for JUnit beginners

Hello everyone,

Today I want share a video for JUnit beginners like us.

“Java Unit Testing with JUnit – Tutorial – How to Create And Use Unit Tests”

By Coding with John

Here is the link: https://www.youtube.com/watch?v=vZm0lHciFsQ

I highly recommend everyone to watch this video before doing Homework 1. Because the function we want to implement on Homework1 is almost logically very similar to what he described. The blogger introduces the working principle of JUnit almost from scratch, and shows step by step how to create a Test Method and its working logic.

For example, From 3 to 10 minutes into the video, he introduces the structure of the Test method, including the use of calculation methods and assert statements.

@Test

void twoPlusTwoShouldEqualFour(){

var calculator = new SimpleCalculator();

assertEquals(expected:4, calculator. add(numberA: 2, unmberB: 2)

}

The above code shows us that if unmberA plus numberB equals 4, then we can pass the test. If it is not 4, it will fail to pass. It also shows us the various functions of assert statement. Such as assertEquals, assertNotEquals, assertTrue, assertFalse, assertNull and so on. We gonna use all of them in every scenario.

Next, the video talks about a more complicated testing method. When there are multiple results, we need to test every scenario that may occur. And he talks about some loopholes in the testing logic. For example, in 15 minutes, he gives an example The condition of return C was changed from 80 to 81, and it still passed the test, even though 80 should return B. This does not mean that our test scenario is bad, but we may need more code to describe the test conditions.

However, I recommend this video because it is really suitable for beginners. When I watched this video, many questions were solved. Although these are very basic things, everything you need to learn later is based on these foundations. I believe that learning the knowledge taught in the video will be very beneficial to our future study. I will follow this blogger. The knowledge he talks about is very easy to absorb and understand.

From the blog CS@Worcester – Ty-Blog by Tianyuan Wang and used with permission of the author. All other rights reserved by the author.

About my blog for CS-443

Hi everyone,

This is Tianyuan Wang, you can call me Ty.
Here is the blog I just created, which will be used for me to learn and record knowledge about CS-443 Software Quality Assur & Test.

I will post and share my questions, experiences and learnings here.

First of all, before learning how to test software specifically, I would like to talk about my understanding and expectations for this course. My understanding of software testing is the process of verifying that the software logic is correct, the functions are complete, the system is safe and the quality is reliable. These are necessary for any software, whether old or new. For example, before a brand new software is released or after an old software is upgraded, professionals must operate the software under specified conditions to discover program errors. The process of measuring software quality and evaluating whether it meets design requirements.

That was my first impression of the CS-443, and I was ready to learn more about it.

From the blog CS@Worcester – Ty-Blog by Tianyuan Wang and used with permission of the author. All other rights reserved by the author.

About my blog for CS-443

Hi everyone,

This is Tianyuan Wang, you can call me Ty.
Here is the blog I just created, which will be used for me to learn and record knowledge about CS-443 Software Quality Assur & Test.

I will post and share my questions, experiences and learnings here.

First of all, before learning how to test software specifically, I would like to talk about my understanding and expectations for this course. My understanding of software testing is the process of verifying that the software logic is correct, the functions are complete, the system is safe and the quality is reliable. These are necessary for any software, whether old or new. For example, before a brand new software is released or after an old software is upgraded, professionals must operate the software under specified conditions to discover program errors. The process of measuring software quality and evaluating whether it meets design requirements.

That was my first impression of the CS-443, and I was ready to learn more about it.

From the blog CS@Worcester – Ty-Blog by Tianyuan Wang and used with permission of the author. All other rights reserved by the author.