1. 程式人生 > >使用junit進行併發測試

使用junit進行併發測試

下面的程式碼將演示如何使用NUnit進行併發測試,啟動多執行緒插入多個數據,並在插入完資料後刪除資料

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using WYEng.SQLServerDAL;
using System.Threading;
using System.Data;
using System.Data.SqlClient;

namespace WYEng.TestUnit
...{
[TestFixture]
public class ExamComputerInfo
...{
SQLServerDAL.ExamComputerInfo computerInfo;
WYEng.Model.ExamComputerInfo mCompuerInfo;
private int j = 0;
private int computerID = 0;
private string PARAM_COMPUTERID = "@ComputerID";
[SetUp]
public void CreateObject()
...{
computerInfo = new WYEng.SQLServerDAL.ExamComputerInfo();
mCompuerInfo = new WYEng.Model.ExamComputerInfo();
TestGetComputerID();
}

[TearDown]
public void DeleteObject()
...{
TestDeleteComputerInfo();
computerInfo = null;
mCompuerInfo = null;

}
private void TestGetComputerID()
...{
computerID = XPWY.DBUtility.DBHelperSQL.GetMaxID("ComputerID", "ExamComputerInfo");
}
private void TestDeleteComputerInfo()
...{
Console.WriteLine(computerID.ToString());
string strSql = "DELETE FROM ExamComputerInfo WHERE ComputerID>

[email protected]";
SqlParameter pram = new SqlParameter(PARAM_COMPUTERID, SqlDbType.Int);
pram.Value = computerID;
XPWY.DBUtility.DBHelperSQL.ExecuteSql(strSql,pram);
}
[Test]
[Ignore("為了測試併發插入的問題,遮蔽該方法")]
public void GetComputerInfo()
...{
Thread[] threads = new Thread[1000];
for (int i = 0; i < 1000; i++)
...{
Thread t = new Thread(new ThreadStart(Func));
threads[i] = t;
}
for (int i = 0; i < 1000; i++)
...{
threads[i].Start();
}


}
private void Func()
...{
mCompuerInfo = computerInfo.GetComputerInfo(1);
Assert.AreEqual(mCompuerInfo.ComputerName, "YMF-XPWY");
}
[Test]
public void GetComputerInfoByMAC()
...{
mCompuerInfo = computerInfo.GetComputerInfoByMAC("00:1B:FC:64:6C:A3");
Assert.AreEqual(mCompuerInfo.ComputerName, "YMF-XPWY");//正常條件
mCompuerInfo = computerInfo.GetComputerInfoByMAC("00:sdfsdfsdf");
Assert.AreEqual(mCompuerInfo, null);//邊界條件
}

[Test]
public void TestInsertCPInfoWhileMorePeoper()
...{
Thread[] threads = new Thread[1000];
for (int i = 0; i < 1000; i++)
...{
j++;
threads[i] = new Thread(new ThreadStart(TestInsertCPInfo));
threads[i].Start();
}
}
private void TestInsertCPInfo()
...{
mCompuerInfo.AudioDapater = j.ToString();
mCompuerInfo.BrowserInfo = j.ToString();
mCompuerInfo.ComputerName = "fw";
mCompuerInfo.EthernetAddress = "asdsad";
mCompuerInfo.ExamSeatNo = j;
mCompuerInfo.IpAddress = "192.168.0.1";
mCompuerInfo.IsTestPassed = true; ;
mCompuerInfo.NotPassedError = "yes";
mCompuerInfo.OSName = "OSName";
mCompuerInfo.OSVersion = "1.0.1";
computerInfo.InsertCPInfo(mCompuerInfo);
}
}
}

相關推薦

使用junit進行併發測試

下面的程式碼將演示如何使用NUnit進行併發測試,啟動多執行緒插入多個數據,並在插入完資料後刪除資料 using System;using System.Collections.Generic;using System.Text;using NUnit.Framework;

使用MockMVC與Junit進行單體測試

eval mvc obj abs nco tps 測試 nal pub 1、pom.xml追加 junit spring-test 2、測試共通類 @ContextConfiguration(locations = { "classpath:springframewo

【轉載】IntelliJ IDEA配置JUnit進行單元測試

dbd ima pom.xml format height eight nsh 格式 oot 前提條件 安裝JDK,並配置好環境變量 工程已解決JUnit依賴關系(pom.xml) IDEA中JUnit配置 IDEA自帶一個JUnit插件,打開Settings窗口搜

IDEA 自動生成Junit進行單元測試

沒有 src ner acc 路徑 name cep csdn ctr 1,從插件資源庫中搜索JunitGenerator V2.0版本,通過此工具自動完成test類的生成。Settings > Plugins 2,配置生成test類的路徑。Settings &

如何開始用Junit進行單元測試

nbsp gif isp public aik 分享 pan 因此 可操作性 近段時間,公司預備推動單元測試以提高轉測代碼的質量,借鑒學習一些測試大佬的經驗自己試了一把,小測我在此寫下初寫單元測試的心得,希望能和大家交流交流單元測試技術! 一、概述 1、 單元測試(

在eclipse中使用JUnit進行單元測試

1、新建java專案 file——new——Java Project 2、新建class檔案 在src上右擊——New——Class 3、配置Junit環境 在Test上右擊——Properties 點選Java Build Path,然後點

使用JUNIT進行單元測試

eclipse如何使用junit部署測試 在要測試的類java檔案上右鍵,選擇New -> Junit Test Case/Suite https://mvnrepository.com/artifact/org.junit/junit5-engine/5.0.0-ALPHA 在專案上右鍵 Ru

IntelliJ IDEA使用Junit進行單元測試

針對MAVEN工程中進行Junit進行單元測試 1、在src目錄先建立一個和main同等級的資料夾 2、然後右鍵test資料夾,設定為測試專用資料夾,然後在在下面建立一個java目錄路徑,根據main資料夾程式碼的路徑建立對用的多級目錄 3、然後進入類中建立對應的Test類 右鍵類名,進

Gradle進階:2: 結合JUnit進行單體測試

在前面一篇文章中介紹瞭如何在spring boot的專案中使用gradle進行構建,這篇文章將會給這個例子新增單體測試。 事前準備 環境準備 元件/框架 版本 JDK 1.8.0

使用junit進行單元測試的註解的執行順序。

轉自:http://zhidao.baidu.com/link?url=chYfV-VFu4cK8t_sAMpYCglk-zl_JHlvx-9ink9sdD_LcrGnfBCrJJ2w2yOaDWyPGg9-ruGVdlt3Q8uLHxxLOt6u42uwBcdnsdzjM

在IDEA中使用JUnit進行方法測試

1.情景設定 現有一個類BhCallRecordServiceImpl,有如下方法 /** * @Auther: liang * @Date: 2018/12/17 14:48 * @Description: */ @Service public class BhCallReco

SpringBoot+Junit進行單元測試

在測試類上新增 @RunWith(SpringRunner.class) @SpringBootTest(classes=MyApplication.class) 這樣就可正常使用@autowi

Spring結合junit進行單元測試

[{PASSWORD=1, LOGINID=a, ID=1083caa8-9143-11e6-945d-708e78b00b24, CREATETIME=2016-10-24 20:39:56.0, BIRTHDAY=2016-10-15 17:48:59.0, NAME=aa, AGE=12}] 1 成功

IDEA中利用JUnit進行單元測試

開啟IntelliJ IDEA工具,Alt+Ctrl+S,彈出視窗如下: 在文字框中輸入Plugin進行外掛搜尋設定。 點選按鈕,從外掛資源庫中安裝新的外掛。 從外掛資源庫中搜索JunitGenerator V2.0版本,在外掛位置,滑鼠右擊 選擇Do

使用spring配合Junit進行單元測試的總結

最近公司的專案和自己的專案中都用到了spring整合junit進行單元測試,總結一下幾種基本的用法: 1.直接對spring中注入的bean進行測試(以DAO為例): 在測試類上新增@RunWith註解指定使用springJunit的測試執行器,@ContextCon

如何使用Junit進行單元測試

我們在編寫大型程式的時候,常常需要寫千上萬個方法或函式,這些函式的功能強大,但我們在程式中只用到該函式的一小部分功能,每編寫完一個函式之後,我們都應該對這個函式的方方面面進行測試,這樣的測試我們稱之為

使用jMeter對基於SAP ID service進行Authentication的Restful API進行併發測試

這篇文章本來Jerry只在SAP社群上寫了英文版的,可以通過點選文末的“閱讀原文”獲得。後來有兩位做Marketing Cloud

使用CodeBenchmark對邏輯程式碼進行併發測試

一直對效能測試比較感興趣,所以也寫了不少的測試工具有WebApiBenchmark和TcpBenchmark等;但這些工具測試都是有針對性和配置的方式來進行功能有限所以很難適用更多的場景,所以單獨開發一個元件CodeBenchmark來解決不同業務程式碼下的效能測試;嚴格來說CodeBenchmark並不算一

通過JUnit進行Android單元測試

2個 nvi frame oncreate protected [] 命令 lib 是我 要了解android單元測試,首先必須了解junit 什麽是 JUnit ? JUnit是采用測試驅動開發的方式,也就是說在開發前先寫好測試代碼,主要用來說明被測試的代碼會被如

Spring基礎:快速入門spring boot(8):使用Junit進行測試

使用Junit或者TestNG可以進行單體測試,這篇文章簡單說明一下如何在Spring boot的專案中使用Junit進行單體測試。 pom設定 pom中需要新增spring-boot-starter-test <dependency> <g