单元测试执行流程

流程简写如下:
class setup -> instance setup -> one test case -> instance tear down -> instance setup -> one test case -> instance tear down -> … -> class tear down

直接show code

python

class SoundTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        print('set up class')

    @classmethod
    def tearDownClass(cls) -> None:
        print('tear down class')

    def setUp(self) -> None:
        print('set up')

    def tearDown(self) -> None:
        print('tear down')

    def test_hello1(self):
        print('hello1')

    def test_hello2(self):
        print('hello 2')

输出结果
Launching unittests with arguments python -m unittest sound.SoundTest in D:\code\python\python-demo\test_package\sound

Ran 2 tests in 0.002s

OK
set up class
set up
hello1
tear down
set up
hello 2
tear down
tear down class

Process finished with exit code 0

java

import org.junit.After;
import org.junit.AfterClass;

import org.junit.Before;
import org.junit.BeforeClass;

import org.junit.Ignore;
import org.junit.Test;

public class ExecutionProcedureJunit {
	
   //execute only once, in the starting 
   @BeforeClass
   public static void beforeClass() {
      System.out.println("in before class");
   }

   //execute only once, in the end
   @AfterClass
   public static void  afterClass() {
      System.out.println("in after class");
   }

   //execute for each test, before executing test
   @Before
   public void before() {
      System.out.println("in before");
   }
	
   //execute for each test, after executing test
   @After
   public void after() {
      System.out.println("in after");
   }
	
   //test case 1
   @Test
   public void testCase1() {
      System.out.println("in test case 1");
   }

   //test case 2
   @Test
   public void testCase2() {
      System.out.println("in test case 2");
   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值