使用Mockito示例页面中最基本的示例,我能够在JUnit中成功运行.
但是,当我在Spock中运行相同的测试时,它会失败.
JUnit/Java版本(通过):
import org.junit.Test;
import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
public class SimpleJunitTest
{
@Test
public void basicMockTest()
{
List mockedList = mock(List.class);
//using mock object
mockedList.add("one");
mockedList.clear();
//verification
verify(mockedList).add("one");
verify(mockedList).clear();
}
}
Run Code Online (Sandbox Code Playgroud)
Spock/Groovy版本(失败):
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.verify
class SimpleSpockTest extends spock.lang.Specification
{
def "Basic Mock Test"()
{
given:
//mock creation
List mockedList = mock(List.class);
when:
//using mock object
mockedList.add("one");
mockedList.clear();
then:
//verification
verify(mockedList).add("one");
verify(mockedList).clear();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在Spock测试失败时得到的错误:
Condition not satisfied:
verify(mockedList).add("one")
| …Run Code Online (Sandbox Code Playgroud) 使用ASP.NET MVC 4和NuGet管理包.
升级到jQuery 1.9.1via后NuGet,我开始收到JavaScript关于删除live()函数的错误jQuery 1.9.x.
我点击F5从VS.NET运行调试模式,进入登录页面,得到以下信息:

发现这个StackOverflow答案:https://stackoverflow.com/a/14512797 并进行了4次更改~\Scripts\jquery.unobtrusive-ajax.js.
我的~\Scripts\jquery.unobtrusive-ajax.js:
$(document).on("click", "a[data-ajax=true]", function (evt) {
...
});
$(document).on("click", "form[data-ajax=true] input[type=image]", function (evt) {
...
});
$(document).on("click", "form[data-ajax=true] :submit", function (evt) {
...
});
$(document).on("submit", "form[data-ajax=true]", function (evt) {
...
});
Run Code Online (Sandbox Code Playgroud)
我也物理删除jquery.unobtrusive-ajax.min.js并用于WebGrease 1.3.0从我的更新中重新生成它~\Scripts\jquery.unobtrusive-ajax.js.
但是,出于某种原因,我对不使用该.live()功能的更改并不坚持.我尝试停止运行MVC应用程序的IIS Express 8.0网站(localhost:63798).
在尝试再次运行F5以在调试模式下运行之前,还尝试执行Build-> Clean Solution,Build-> Rebuild Solution.
如果有人以前经历过这个并且有任何见解,我将非常感激.先感谢您.
asp.net-mvc jquery asp.net-mvc-4 unobtrusive-ajax visual-studio-2012
我正在编写一个简单的AngularJS控制器来跟踪检查的复选框的数量.试图避免$scope.$watch使用ng-change增加/减少总计数.
HTML:
<form ng-controller="MainCtrl">
<table>
<tr ng-repeat="item in data">
<td>
<input type="checkbox"
value="{{item.id}}"
ng-model="item.selected"
ng-change="updateTotal($event)"> {{item.name}}
</td>
</tr>
</table>
<p>
Total checked: {{totalSelected}}
</p>
</form>
Run Code Online (Sandbox Code Playgroud)
控制器片段
$scope.updateTotal = function($event) {
var checkbox = $event.target;
if (checkbox.checked) {
$scope.totalSelected++;
}
else {
$scope.totalSelected--;
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在尝试访问的控制器中收到错误$event.target:
TypeError: Cannot read property 'target' of undefined
Run Code Online (Sandbox Code Playgroud)
我创建了一个用于重新创建的Plunk:http://plnkr.co/edit/qPzETejmMHHZCQ2sV2Sk?p = info
如果有人有任何想法或建议,我将非常感激.
非常感谢你!
我的发布配置文件已损坏.
我需要删除它.我的另一台电脑很好,所以我知道它是本地的.
我试过了:
从Git中清除代码库的检查(因此我的代码目录中没有任何内容).
删除 C:/Users/<user>/AppData/Local/VisualStudio
C:/Users/<user>/AppData/Roaming/VisualStudio尽管如此,VS.NET仍然存在于已损坏的Publish配置文件中.
老实说,我在斗智斗勇,我的下一个重大步骤是重新安装Windows 10. 请提供帮助!
我目前正在阅读并使用Scott Davis和Jason Rudolph撰写的Grails入门版第二版中的示例.
这本书是用Grails 1.2编写的.
他们有一个代码示例,他们在这里创建一个debug()被调用的方法,beforeInterceptor并解释说,既然debug()是一个方法,它就不会通过URL暴露给用户.他们解释说,Closures作为Controller Actions暴露给最终用户,但方法却没有.
我还在Grails 1.3文档中看到,他们提到了常规方法:
def auth() { ... }
Run Code Online (Sandbox Code Playgroud)
被视为私有,因为它是一个方法,而不是一个闭包.从Grails 1.3开始就是如此.
但是,从Grails 2.0.0开始,Controller Actions可以作为方法和闭包实现.
这让我想知道(并试图找出)一种方法来复制Grails 2.0.0之前在Controller中创建方法时可用的功能,该方法不会暴露给最终用户.
我想到了两种可能的方法,并且想知道哪种风格/做法更好,为什么?
private def auth()为该方法设置allowedMethods以清空字符串:
static allowedMethods = [save: "POST", update: "POST", delete: "POST", auth: ""]
Run Code Online (Sandbox Code Playgroud)这两种方法似乎都达到了预期的效果.但是,第一种方法给出HTTP错误代码404,第二种方法给出HTTP错误代码405.
有谁知道哪种方法更可取?此外,还有其他方法,或"最佳实践技术"吗?
我正在使用Grails 2.1.1和MySQL 5.5.27 Community Server.
我需要一个Domain类字段生成一个TEXT或LONGTEXT列.
我觉得这很简单,我看过很多例子:
但是,我整晚都遇到了死胡同.我遵循了所有这些例子,似乎都没有工作(即使其他人报告它有效).
以下是我创建的域类示例:
class Coltest {
static constraints = {
description1 sqlType: 'longtext'
description2 sqlType: 'text'
description3 type: 'text'
description4 column: "longDescription", type: "text", nullable:true
}
String description1
String description2
String description3
String description4
}
Run Code Online (Sandbox Code Playgroud)
这是我在MySQL命令界面中得到的:
mysql> describe coltest;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到IntelliJ IDEA 12.0并在尝试启动时立即收到错误:
The JVM could not be started. The maximum heap size (-Xmx) might be too large or
an antivirus or firewall tool could block the execution.
Run Code Online (Sandbox Code Playgroud)
我检查了我的idea.exe.vmoptions文件,最大堆大小只有640米(我有8 GB物理内存,并没有运行任何其他应用程序).
idea.exe.vmoptions
-Xms128m
-Xmx640m
-XX:MaxPermSize=640m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-ea
-Dsun.io.useCanonCaches=false
Run Code Online (Sandbox Code Playgroud)
我仍然IntelliJ IDEA 11.4在我的机器上运行它(使用相同的max heapsize值idea.exe.vmoptions).自IntelliJ IDEA 11.4运行以来,我不认为它是防病毒或防火墙问题.我也检查过这些设置.
任何人遇到这个或有任何想法(没有双关语)?
我正在使用Grails 2.1.1并希望添加一些映射到Controller Actions的自定义URL.
我可以这样做,但原始的映射仍然有效.
例如,我add-property-to-directory在my中创建了一个映射,UrlMappings如下所示:
class UrlMappings {
static mappings = {
"/add-property-to-directory"(controller: "property", action: "create")
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
Run Code Online (Sandbox Code Playgroud)
现在,正如我所料,我可以击中/mysite/add-property-to-directory并执行它PropertyController.create.
但是,我仍然可以击中/mysite/property/create它,它将执行相同的PropertyController.create方法.
在干燥的精神,我想从做301重定向/mysite/property/create到/mysite/add-property-to-directory.
我找不到办法做到这一点UrlMappings.groovy.有谁知道我可以在Grails中实现这一目标的方式?
非常感谢你!
UPDATE
根据Tom的回答,这是我实施的解决方案:
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/add-property-to-directory"(controller: "property", action: "create")
"/property/create" {
controller = "redirect"
destination = "/add-property-to-directory"
}
"/$controller/$action?/$id?"{
constraints { …Run Code Online (Sandbox Code Playgroud) 我可以在我的关于AngularJS 2.0 TypeScript Intellij想法(或webstorm) - ES6导入语法的 Stackoverflow答案中使用AngularJS 2.0 5分钟快速入门.IntelliJ IDEA 14.1.4
然而,这似乎是针对编译TypeScript到EcmaScript 5.
我想看看我是否可以AngularJS 2.0 Typescript编译EcmaScript 6.
问题1:当我将TypeScript编译器更改为目标时ES6...
我开始收到TypeScript编译器错误:
Error: TS1204: Cannot compile modules into 'commonjs', 'amd', 'system', or 'umd'
when targeting 'ES6' or higher.
Run Code Online (Sandbox Code Playgroud)
我可以通过删除--module "amd" TypeScript编译器选项来解决它.
这确实提出了一个问题:没有指定amd,使用什么样的模块格式ES6?
问题2:
修改TypeScript编译器选项后,它们显示如下:
我开始收到以下错误:
Error TS2300: Duplicate identifier 'Promise'
Run Code Online (Sandbox Code Playgroud)
谁看过这个吗?我怀疑它与AngularJS 2.0 Quickstart指定ES-6 Promise有关,它在全球范围内安装,但无法弄清楚如何解决它.
非常感谢你提前.
所有,
如果这是世界上最愚蠢的问题,我道歉.
我发现了这个:https://stackoverflow.com/a/155363/463196
我想我需要一个虚拟对象的视觉演练,除非这已经从VS.NET 2008和VS.NET 2017发生了变化.
编辑:
我需要这个的原因......我正在做C#,Azure.有一个环境变量,如果设置为Debug,将使存储转到模拟而不是实时Azure存储.我需要这个,以便我可以愉快地从测试到Prod w/out触摸我的App.Config文件.
grails ×3
grails-2.0 ×3
c# ×2
groovy ×2
java ×2
angular ×1
angularjs ×1
asp.net-mvc ×1
azure ×1
checkbox ×1
ecmascript-6 ×1
git ×1
grails-orm ×1
javascript ×1
jquery ×1
junit ×1
mockito ×1
mysql ×1
spock ×1
typescript ×1