junit同时执行多个测试类
junit同时执行多个测试类
JavaSon712 发表于6个月前
junit同时执行多个测试类
  • 发表于 6个月前
  • 阅读 6
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】如何购买服务器最划算?>>>   

摘要: https://examples.javacodegeeks.com/core-java/junit/junit-runwith-example/

创建被测试类FirstDayAtSchool.java

package com.javacodegeeks.junit.suite;

import java.util.Arrays;

public class FirstDayAtSchool {
	public String[] prepareMyBag() {
		String[] schoolbag = { "Books", "Notebooks", "Pens" };
		System.out.println("My school bag contains: "
				+ Arrays.toString(schoolbag));
		return schoolbag;
	}

	public String[] addPencils() {
		String[] schoolbag = { "Books", "Notebooks", "Pens", "Pencils" };
		System.out.println("Now my school bag contains: "
				+ Arrays.toString(schoolbag));
		return schoolbag;
	}
}

创建第一个测试类FirstDayAtSchoolTest.java

package com.javacodegeeks.junit.suite;

import static org.junit.Assert.*;

import org.junit.Test;

public class FirstDayAtSchoolTest {

	FirstDayAtSchool school = new FirstDayAtSchool();
	String[] bag = { "Books", "Notebooks", "Pens" };

	@Test
	public void testPrepareMyBag() {
		System.out.println("Inside testPrepareMyBag()");
		assertArrayEquals(bag, school.prepareMyBag());
	}

}

创建第二个测试类FirstDayAtSchoolTest2.java

package com.javacodegeeks.junit.suite;

import static org.junit.Assert.*;

import org.junit.Test;

public class FirstDayAtSchoolTest2 {

	FirstDayAtSchool school = new FirstDayAtSchool();
	String[] bag = { "Books", "Notebooks", "Pens", "Pencils" };

	@Test
	public void testAddPencils() {
		System.out.println("Inside testAddPencils()");
		assertArrayEquals(bag, school.addPencils());
	}

}

同时执行两个测试类AllTests.java

package com.javacodegeeks.junit.suite;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ FirstDayAtSchoolTest.class, FirstDayAtSchoolTest2.class })
public class AllTests {

}
标签: java JUnit
共有 人打赏支持
粉丝 6
博文 96
码字总数 22080
×
JavaSon712
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: