這兩天在看清華大學最近出的一個關于deepseek入門的官方視頻中,看了幾個deepseek的應用場景還是能夠感覺到它的強大之處的,例如根據需求生成各種markdown格式的代碼,再結合市面上已有的一些應用平臺生成非常好看的流程圖,PPT,報表等,看到了一個使用Cursor 結合deepseesk 快速生成了幾個小工具的例子,感覺還是蠻驚艷的, 然后就下載來試用了下,此時又想起了之前看到的一張圖,阿里前端第一人玉伯,語雀創始人發的一條動態。
?
看來Cursor 還不如Devin 高效,先熟悉下 Cursor,后面再試用下Devin
Cursor的安裝設置還是很簡單的,并且還有兩周的免費試用時間,可以加載各種大模型,簡單配置即可,然后其實就相當于一個類似Vcode的前端開發工具。
簡單讓Cursor搭個前端頁面,實現基本的增刪查改:
一個簡單的html 頁面幾分鐘就搞定了,還符合了個人輸入的各種訴求,雖然也沒有連數據庫,沒有部署服務這些,但是極大減少了敲代碼的時間的。
那么,和測試相關可以做什么呢?實際工作,測試就是集各個崗位功能于一身,自己寫需求,自己實現前后端,很多時候感覺花費在前端的時間比后端實現還要多很多,一個因為不熟悉,而是因為頁面功能樣式老是調來調去,若能借助AI 來減少這部分時間的投入,還是非常可以的。
讓deepseek 生成一個上傳需求文檔,寫測試用例的界面
?
明顯上面的例子只是簡單的文本處理,那么讓它使用NLP 來對文本進行分析處理。
這個上下文都還記得,仍然記得但是chatGPT 無法記住前面對話的難用之處。
關于NLP 的常用功能:
?
執行后頁面報錯:
?
deepseek 又給出了可能的錯誤信息:
報錯排查,完美給出各種可能原因和解決方案,高效呀高效:
發現控制臺可以nlp分析的日志了,沒有數據:
?
看來這個解析也是有問題:
那么使用deepseek呢?還是很快就給出了實現代碼,這里還要用到相關的api key ,要不就是本地部署deepseek來調用本地的接口了,給出的代碼實現還是很詳細的。
通過調用deepseek 的api接口來生成數據。
?
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>測試用例生成器</title><style>body { font-family: Arial, sans-serif; margin: 20px; }.container { max-width: 800px; margin: 0 auto; }textarea { width: 100%; height: 150px; margin: 10px 0; }.test-case { border: 1px solid #ddd; padding: 15px; margin: 10px 0; }.test-case h3 { margin-top: 0; }.loading { display: none; color: #888; }</style>
</head>
<body><div class="container"><h1>測試用例生成器</h1><div><h2>上傳需求文檔</h2><input type="file" id="doc-upload" accept=".txt"></div><div><h2>或直接輸入需求</h2><textarea id="requirement-input" placeholder="在此輸入需求描述..."></textarea><button onclick="handleAnalyze()">生成測試用例</button><div id="loading" class="loading">生成中,請稍候...</div></div><div id="test-cases-container"><h2>生成的測試用例</h2></div></div><script>const DEEPSEEK_API_KEY = 'YOUR_DEEPSEEK_API_KEY'; // 替換為你的 DeepSeek API 密鑰const DEEPSEEK_API_URL = 'https://api.deepseek.com/v1/chat/completions'; // DeepSeek API 地址// 全局函數,用于處理分析請求function handleAnalyze() {analyzeRequirement();}// 全局需求分析函數async function analyzeRequirement(input) {const requirement = input || document.getElementById('requirement-input').value;if (!requirement.trim()) {alert('請輸入或上傳需求文檔');return;}try {showLoading(true);const testCases = await generateTestCasesWithDeepSeek(requirement);displayTestCases(testCases);} catch (error) {console.error('生成測試用例失敗:', error);alert('生成測試用例失敗,請重試');} finally {showLoading(false);}}// 使用 DeepSeek API 生成測試用例async function generateTestCasesWithDeepSeek(requirement) {const prompt = `根據以下需求生成測試用例,格式為:前置條件,執行步驟,預期返回。需求:${requirement}`;const response = await fetch(DEEPSEEK_API_URL, {method: 'POST',headers: {'Content-Type': 'application/json','Authorization': `Bearer ${DEEPSEEK_API_KEY}`},body: JSON.stringify({model: 'deepseek-chat',messages: [{ role: 'user', content: prompt }],max_tokens: 1000})});if (!response.ok) {throw new Error('API 請求失敗');}const data = await response.json();const testCasesText = data.choices[0].message.content;return parseTestCasesFromText(testCasesText);}// 解析 DeepSeek 返回的測試用例文本function parseTestCasesFromText(text) {const testCases = [];const lines = text.split('\n');let currentCase = {};lines.forEach(line => {if (line.startsWith('前置條件:')) {currentCase.precondition = line.replace('前置條件:', '').trim();} else if (line.startsWith('執行步驟:')) {currentCase.steps = line.replace('執行步驟:', '').trim();} else if (line.startsWith('預期返回:')) {currentCase.expected = line.replace('預期返回:', '').trim();testCases.push({ ...currentCase, id: testCases.length + 1 });currentCase = {};}});return testCases;}// 顯示生成的測試用例function displayTestCases(testCases) {const container = document.getElementById('test-cases-container');container.innerHTML = '<h2>生成的測試用例</h2>';testCases.forEach(testCase => {const testCaseDiv = document.createElement('div');testCaseDiv.className = 'test-case';testCaseDiv.innerHTML = `<h3>測試用例 #${testCase.id}</h3><p><strong>前置條件:</strong>${testCase.precondition}</p><p><strong>執行步驟:</strong>${testCase.steps}</p><p><strong>預期返回:</strong>${testCase.expected}</p>`;container.appendChild(testCaseDiv);});}// 文件上傳處理document.getElementById('doc-upload').addEventListener('change', function(event) {const file = event.target.files[0];if (file) {const reader = new FileReader();reader.onload = function(e) {const content = e.target.result;analyzeRequirement(content);};reader.readAsText(file);}});// 顯示/隱藏加載狀態function showLoading(isLoading) {document.getElementById('loading').style.display = isLoading ? 'block' : 'none';}</script>
</body>
</html>
看到b站有各種關于多少分鐘借助Cursor生成小程序上線的視頻,還沒實踐過,但是或許不久的將來,程序員這個崗位,是不是真的要下線了?
?
這篇文章,讓deepseek 給我生成個標題,好吧,這是一點都不謙虛,自賣自夸~感覺科技進步帶來的就是人的腦子好像都不需要怎么用了,最終決定,還是用我自己隨便想的~
?
有時候感覺AI發展日新月異的同時,人在其面前顯得十分渺小,也會不斷的對個人的價值感產生懷疑,很多事情當你細想的時候就會容易感覺到虛無,好像只能讓自己停止去想,才會有動力去做一些看似無意義的事情,maybe 過程很重要,在這個過程中個人的體驗也很重要~目前AI 給我的感覺就是能一路見證它的飛飛飛飛飛飛飛飛飛飛飛速發展,然后緊隨其后學到點或者知道點什么,也許也是一件還挺有意思的事情吧~
(凌晨2點了,咖啡喝太多的后果~)