EE308 LAB11

ZHENGYU-831901211 2022-01-03 20:05:58
The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZ
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/603781458
The Aim of This AssignmentCourse Summary
MU STU ID and FZU STU ID19105681  831901211

Preparation

Learn related knowledge about Junit Test for Java and Unittest for python. You can finish the following assignment or test Your Project.

 

Task

  1. Here are Junit Test task and Unittest task for choose. If you are good at Java , we suggest you choose the first one, if you are good at Python, then, the latter one.
  2. Follow the requests and tips, complete the test task .

 

Requirements

  1. You should be familiar with Junit Test or Unittest and the usage of these tools.Such as ‘assert, suite, timeout’, check problems for detail.
  2. Fix the missing codes according to requirement for every problem.

 

Tips:

  • We list ‘related knowledge’ for some problems, read it very carefully

    Unittest based on python

    1.unittest assert test

  • import unittest, random
     
     
    # Test Class
    class MyClass(object):
     
        @classmethod
        def sum(self, a, b):
            return a + b
     
        @classmethod
        def div(self, a, b):
            return a / b
     
        @classmethod
        def retrun_None(self):
            return None
     
     
    # Unit Test Class
    class MyTest(unittest.TestCase):
        # assertEqual()
        def test_assertEqual(self):
            # test if a+b equals sum or not
            try:
                a, b = 1, 2
                sum = 3
                self.assertEqual(a + b, sum, 'assert failed!,%s + %s != %s' % (a, b, sum))
            except AssertionError as e:
                print(e)
     
        # assertNotEqual()
        def test_assertNotEqual(self):
            # fix missing three lines of codes below ‘try’, test if b-a equals res or not
            try:
                a, b = 1, 3
                res = 3
                self.assertNotEqual(b - a, res, 'assert failed!,%s + %s != %s' % (a, b, res))
            except AssertionError as e:
                print(e)
     
        # assertTrue()
        def test_assertTrue(self):
     
            try:
                self.assertTrue(1 == 1, "False expression")
            except AssertionError as e:
                print(e)
     
        # assertFalse()
        def test_assertFalse(self):
            # fix missing codes below ‘try’, only a line of codes needed
            try:
                self.assertFalse(1 != 1, "False expression")
            except AssertionError as e:
                print(e)
     
        # assertIs()
        def test_assertIs(self):
            # test a and b are totally same
            try:
                a = 12
                b = a
                self.assertIs(a, b, "%s and %s are not same" % (a, b))
            except AssertionError as e:
                print(e)
     
        # assertIsInstance()
        def test_assertIsInstance(self):
            # fix missing codes below ‘y=object’ to test type(x) != y, only a line of codes needed
            try:
                x = MyClass
                y = object
                self.assertIsNot(x, y, "%s and %s are not same" % (x, y))
            except AssertionError as e:
                print(e)
     
     
    if __name__ == '__main__':
        # run unittest
        unittest.main()

  • result of this test:


  • import static org.junit.Assert.*;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Suite;
    import Help.Calculate;
    import Help.CalculateTest;
    import Help.Car;
    import Help.CarTest;
     
    /*
    add two lines of annotations. Implement Suite Test of CalculateTest and CarTest
    Suite Test codes must next to Class SuiteTest, no shift allowed!
    */
    //**************************************************************
    @RunWith(Suite.class)
    @Suite.SuiteClasses({ CalculateTest.class, CarTest.class})
    public class SuiteTest {
     
    }

  •  

    Summary

    Through this experiment, I gain a deeper understanding of the code structure used to implement the back end. It is a good chance to improve the writing ability and understanding of the code, and ultimately my testing is successful.

 

...全文
1634 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

183

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程 教学
软件工程 高校
社区管理员
  • 单步调试
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧