Cursor 与DeepSeek的完美契合
这两天在看清华大学最近出的一个关于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点了,咖啡喝太多的后果~)