在之前的项目中,我使用Spock测试框架对我的Java代码进行单元测试.我发现这非常有效,所以我试图将Spock测试添加到我当前的项目中,该项目使用Maven作为其构建工具(之前的项目使用了Gradle).虽然我可以让Maven编译我的Spock测试(使用groovy-eclipse-compiler),但我无法让Maven运行测试.
我做了一个简单的例子来演示我的2个文件的问题:
pom.xmlsrc/test/java/ASpec.groovy内容pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group</groupId>
<artifactId>my-artifact</artifactId>
<version>0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.7-groovy-2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.1.8-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
内容ASpec.groovy:
import spock.lang.Specification
class ASpec extends Specification {
def "Test A"(){
// Always fail
expect: false …Run Code Online (Sandbox Code Playgroud) 我想在网站上发一篇带有java的帖子.我想出了这个,但我不知道接下来要做什么,或者这是否是正确的方法.
URL url = new URL("http://127.0.0.1");
URLConnection conn=url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
Run Code Online (Sandbox Code Playgroud)
帖子表格看起来像这样.
<form action="prikaz4.php" method="post">
<select name="igralec"/>
<option value="Kobe Bryant">Kobe Bryant</option>
<option value="Dwayne Wade">Dwayne Wade</option>
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud) 我有一个静态方法,它将从类中的测试方法调用,如下所示
public class MyClass
{
private static boolean mockMethod( String input )
{
boolean value;
//do something to value
return value;
}
public static boolean methodToTest()
{
boolean getVal = mockMethod( "input" );
//do something to getVal
return getVal;
}
}
Run Code Online (Sandbox Code Playgroud)
我想通过模拟mockMethod为方法methodToTest编写一个测试用例.试图吼叫,它没有任何输出
@Before
public void init()
{
Mockit.setUpMock( MyClass.class, MyClassMocked.class );
}
public static class MyClassMocked extends MockUp<MyClass>
{
@Mock
private static boolean mockMethod( String input )
{
return true;
}
}
@Test
public void testMethodToTest() …Run Code Online (Sandbox Code Playgroud) 我们刚刚将单元测试移植到JUnit5.意识到这仍然是相当早期的采用,在谷歌上几乎没有提示.
最具挑战性的是获得我们在jenkins上使用的Junit5测试的jacoco代码覆盖率.因为这花了我差不多一天才弄明白,我想我分享了.不过,如果您知道更好的解决方案,我很有兴趣知道!
buildscript {
dependencies {
// dependency needed to run junit 5 tests
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
}
}
// include the jacoco plugin
plugins {
id 'jacoco'
}
dependencies {
testCompile "org.junit.jupiter:junit-jupiter-api:5.0.0-M2"
runtime "org.junit.jupiter:junit-jupiter-engine:5.0.0-M2"
runtime "org.junit.vintage:junit-vintage-engine:4.12.0-M2"
}
apply plugin: 'org.junit.platform.gradle.plugin'
Run Code Online (Sandbox Code Playgroud)
然后问题似乎是org.junit.platform.gradle.plugin中定义的junitPlatformTest在gradle生命周期阶段定义太晚,因此在解析脚本时是未知的.
为了仍然能够定义观察junitPlatformTest任务的jacoco任务,需要以下hack.
tasks.whenTaskAdded { task ->
if (task.name.equals('junitPlatformTest')) {
System.out.println("ADDING TASK " + task.getName() + " to the project!")
// configure jacoco to analyze the junitPlatformTest task
jacoco {
// this tool version is compatible with
toolVersion = "0.7.6.201602180812"
applyTo …Run Code Online (Sandbox Code Playgroud) 我想通过Gradle将Checkstyle的输出作为HTML报告.
我在Checkstyle插件文档中找不到任何内容.
我已将以下内容添加到我的build.gradle文件中.
checkstyleTask {
reports {
html {
destination "build/reports/checkstyle.html"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这产生了
出了什么问题:评估根项目'MyProject'时出现问题.
无法在根项目"MyProject"上找到参数[build_1vu33nc0ekgtoo19jt e86o8o42 $ _run_closure8 @ 1d8ee20]的方法checkstyleTask().
有没有办法使用Gradle生成Checkstyle HTML报告?
谢谢.
我配置我的全局~/.gitconfig属性user.name,user.email像这样:
git config --global user.email "mkobit@example.com"
git config --global user.name "mkobit"
Run Code Online (Sandbox Code Playgroud)
这是我想要处理个人项目,开源资料等的默认配置.
当我正在处理来自特定域(例如公司域)的项目时,我在克隆它时为每个存储库配置它,以便它使用不同的user.name/ user.email:
git clone ssh://git@git.mycorp.com:1234/groupA/projectA.git
cd projectA
git config user.email "mkobit@mycorp.com"
git config user.name "m.kobit"
Run Code Online (Sandbox Code Playgroud)
一个不错的选择是设置别名来克隆这些类型的存储库:
git config --global alias.clonecorp 'clone \
-c user.name="m.kobit" -c user.email="mkobit@mycorp.com"'
git clonecorp ssh://git@git.mycorp.com:1234/groupA/projectA.git
Run Code Online (Sandbox Code Playgroud)
这两者都可能容易出错,因为它们都依赖于我的聪明并遵循正确的步骤.有证据表明,这种情况几乎可以保证在某个时候搞砸了.
有没有办法配置Git,以便某个域(mycorp.com在本例中)的存储库将以某种方式配置?
我有这个代码:
task fatJar(type: Jar) << {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'mvc.MvcMain'
}
baseName = project.name + '-all'
with jar
}
Run Code Online (Sandbox Code Playgroud)
我收到了这个警告:
在任务执行时配置复制任务的子规范已被弃用,并计划在Gradle 4.0中删除.请考虑在配置时配置规范,或使用单独的任务进行配置.在build_b2xrs1xny0xxt8527sk0dvm2y $ _run_closure4.doCall
这个警告:
不推荐使用Task.leftShift(Closure)方法,并计划在Gradle 5.0中删除它.请改用Task.doLast(Action).
如何重写我的任务?
很沮丧我找不到这个例子.如何设置默认选项?
parameters {
choice(
defaultValue: 'bbb',
name: 'param1',
choices: 'aaa\nbbb\nccc',
description: 'lkdsjflksjlsjdf'
)
}
Run Code Online (Sandbox Code Playgroud)
defaultValue在这里无效.我希望选择是可选的,并且如果管道是非手动运行(通过提交),则设置默认值.
我写了一个如下任务,但无法理解'|' 呢?
tasks:
- shell: /usr/bin/foo
register: result
ignore_errors: True
- debug: msg="it failed"
when: result|failed
- debug: msg="it changed"
when: result|changed
Run Code Online (Sandbox Code Playgroud)
我也在网上找到了一些例子但是无法理解什么是'|' 呢?
debug: msg={{ ipaddr |replace(",", ".") }}
Run Code Online (Sandbox Code Playgroud)
还有一个例子:
- hosts: localhost
vars:
D:
1 : "one"
2 : "two"
tasks:
- debug: var=D
- debug: msg="D[1] is {{ D[1]|default ('undefined') }}"
Run Code Online (Sandbox Code Playgroud)
如果有人可以详细解释或指向某个URL,那会很棒吗?
任何帮助,将不胜感激.
谢谢.
我在使用AWS Boto3使用推荐的KeyConditionExpression同时使用散列键和范围键查询DynamoDB时遇到问题.我附上了一个示例查询:
import boto3
from boto3 import dynamodb
from boto3.session import Session
dynamodb_session = Session(aws_access_key_id=AWS_KEY,
aws_secret_access_key=AWS_PASS,
region_name=DYNAMODB_REGION)
dynamodb = dynamodb_session.resource('dynamodb')
table=dynamodb.Table(TABLE_NAME)
request = {
'ExpressionAttributeNames': {
'#n0': 'hash_key',
'#n1': 'range_key'
},
'ExpressionAttributeValues': {
':v0': {'S': MY_HASH_KEY},
':v1': {'N': GT_RANGE_KEY}
},
'KeyConditionExpression': '(#n0 = :v0) AND (#n1 > :v1)',
'TableName': TABLE_NAME
}
response = table.query(**request)
Run Code Online (Sandbox Code Playgroud)
当我使用以下方案对表执行此操作时:
Table Name: TABLE_NAME
Primary Hash Key: hash_key (String)
Primary Range Key: range_key (Number)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,我不明白为什么:
ClientError: An error occurred (ValidationException) when calling the Query operation: Invalid …Run Code Online (Sandbox Code Playgroud)