嗨,我使用locustio(python)来测试webapp(django)上的负载.当我尝试测试它时,我总是遇到403错误的挑战.他是代码
from locust import HttpLocust, TaskSet
def index(l):
l.client.get("/")
def login(l):
l.client.post("/login/", {"username":"an@id.com", "password":"education")
def upload(l):
l.client.get("/upload-image/")
def home(l):
l.client.get("/home/")
def settings(l):
l.client.get("/settings/")
def logout(l):
l.client.get("/logout/")
class UserBehavior(TaskSet):
tasks = {index:1, upload:1, home:1, settings:1, logout:1}
def on_start(self):
login(self)
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait=5000
max_wait=9000Run Code Online (Sandbox Code Playgroud)
我正在运行 Spring Boot 2.0.1 和 Junit 5。我试图在集成测试中获取端口。但是端口值始终为零。我不确定是什么原因造成的。我曾尝试将网络环境枚举更改为随机端口,但似乎没有任何效果。
package com.example.demo;
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class DemoApplicationTests {
@LocalServerPort
private int port;
@Test
public void printPort() throws Exception {
assertNotEquals(port, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是pom(注意,仅显示依赖项)
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<junit-jupiter.version>5.2.0</junit-jupiter.version>
<junit-platform.version>1.2.0</junit-platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<scope>test</scope>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> …Run Code Online (Sandbox Code Playgroud)