在C#中,如何在运行时使用.NET Core发出新的Type?我可以在.NET 6中找到的所有示例似乎都不适用于.NET内核(它们都是从获取当前AppDomain开始的,而后者在.NET内核中不再存在).
如果可能的话,我将会感谢一个涉及创建Type并向Type添加属性的示例.
我试图测试我的构造函数将使用Teaspoon gem为Rails抛出错误,ChaiJS作为我的断言库.
当我运行以下测试时:
it('does not create the seat if x < 0', function() {
var badConstructor = function() {
return new Seat({ radius: 10, x: -0.1, y: 0.2, seat_number: 20, table_number: 30});
};
expect(badConstructor).to.throw(Error, 'Invalid location');
});
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
失败:
1) Seat does not create the seat if x < 0
Failure/Error: undefined is not a constructor (evaluating 'expect(badConstructor).to.throw(Error(), 'Invalid location')')
Run Code Online (Sandbox Code Playgroud)
构造函数抛出错误,但我认为我没有正确编写测试.
当我尝试运行expect(badConstructor())然后我得到输出:
Failures:
1) Seat does not create the seat if x < 0
Failure/Error: Invalid location
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个onclick函数,该函数在不使用jQuery的情况下从JavaScript表中返回所单击单元格的行和列.到目前为止我将返回列,但我无法弄清楚如何使它返回行.
**cellToAppend.addEventListener("click", clicked);**
**function clicked() {
alert("clicked cell at: " + (this).cellIndex + ", ");
}**
Run Code Online (Sandbox Code Playgroud) 我正在使用gradle文件来构建我的项目。在此文件中,我正在使用jacoco生成测试报告。我要做的是修改构建文件,以便在我的测试覆盖率不是100%时显示一条消息。或者至少只是显示测试覆盖率。这可能吗?
这是我的build.gradle:
apply plugin: 'java'
apply plugin: 'jacoco'
sourceSets.main.java.srcDirs = ['src']
sourceSets.test.java.srcDirs = ['test']
dependencies {
testCompile group: 'junit', name: 'junit', version: "4.+"
}
repositories {
mavenCentral()
}
jacocoTestReport {
doFirst {
classDirectories = files('build/classes/main/draw')
}
reports {
xml.enabled false
csv.enabled false
html.destination "build/reports/coverageHtml"
}
}
task(runui, dependsOn: jar, type: JavaExec) {
main = 'gui.Main'
classpath = sourceSets.main.runtimeClasspath
}
defaultTasks 'clean', 'test', 'jacocoTestReport', 'runui'
Run Code Online (Sandbox Code Playgroud) 我正在使用FactoryBotin myseeds.rb来填充我的数据库。FactoryBot.在打电话之前我必须先打电话build或者create。有什么办法让我不必这样做吗?另外,我应该用于FactoryBot播种,还是仅用于测试?
注:FactoryBot 以前称为 FactoryGirl
我试图Stripe::Charge.retrieve在我的一些测试中模拟,但出现错误:
Failure/Error: allow_any_instance_of(Stripe::Charge).to receive(:retrieve)
Stripe::Charge does not implement #retrieve
Run Code Online (Sandbox Code Playgroud)
我猜 Stripe API 做了某种反射来生成这个方法。有没有办法模拟这个方法?或者也许是一种关闭 RSpec 功能的方法,该功能验证特定测试是否存在模拟方法?
我正在使用Swing在Java中创建一个小型GUI.所有我想要得到它做的是采取ArrayList的CircleS和吸引他们.我遇到了两个问题:
1)我必须draw在绘制圆圈之前反复调用我的方法.如果我只是draw在没有任何反应时调用我的方法,我会得到一张空白的图纸.如果我在一个运行时间小于30毫秒的循环中调用它,它只会绘制我想要绘制的两个圆圈中的第一个.最后,如果我调用它超过30毫秒,它会绘制我试图绘制的两个圆圈.
和
2)当我移动其中一个圆圈时,我在绘图上出现"闪烁".
我对Swing编程不太熟悉.我查看了示例代码并观看了一些视频 - 以及我对我的看法.但我认为我一定搞砸了,因为在我看过的视频中看起来并不像这样.
这是我的GUI班级:
package gui;
import draw.*;
import java.util.List;
import javax.swing.*;
public class GUI extends JFrame {
private CirclePainter drawingBoard = new CirclePainter();
public GUI()
{
setSize(500, 500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
this.add(drawingBoard);
drawingBoard.setVisible(true);
}
public void draw(List<Circle> circles)
{
drawingBoard.paintComponent(drawingBoard.getGraphics(), circles);
}
}
Run Code Online (Sandbox Code Playgroud)
我的CirclePainter班级
package gui;
import draw.Circle;
import javax.swing.*;
import java.awt.*;
import java.util.List;
class CirclePainter extends JPanel
{
public void paintComponent(Graphics graphics, List<Circle> …Run Code Online (Sandbox Code Playgroud) 我被告知要避免return在Scala中使用,尽管我不确定为什么.
我有以下代码,除非我把return关键字放在那里,它似乎没有返回正确的东西.我为什么要放return?
def nextParen(chars: List[Char]): List[Char] =
for(i <- 0 to chars.size - 1) {
if(chars(i) == '(' || chars(i) == ')') {
return chars.slice(i, chars.size) // return HERE!
}
}
List.empty
}
Run Code Online (Sandbox Code Playgroud) 我想使用jQuery 找到任何canvas带有id的元素whatever.我以为我可以这样做,$('canvas #whatever')但是当我在页面上有一个带有该id的画布时,这不会返回任何内容.
有没有办法测试是否在 RSpec 中使用正确的密码创建了 Devise 用户?
我有一个用于创建用户的功能规范,并已尝试进行测试,created_user.encrypted_password eq User.new(password: same_as_created_user).encrypted_password但生成的密码不匹配。
我在RSpec中存根控制器方法,并且存根工作正常,但是如何确保使用特定输入调用该方法,即我传递给调用此存根方法的方法的哈希?