首页 \ 问答 \ 是否可以在ExUnit测试中存根(模拟?)Ecto.UUID.generate?(Is it possible to stub(mock?) Ecto.UUID.generate in an ExUnit test?)

是否可以在ExUnit测试中存根(模拟?)Ecto.UUID.generate?(Is it possible to stub(mock?) Ecto.UUID.generate in an ExUnit test?)

我正在使用Ecto.UUID.generate在用户模型上创建随机令牌。

在我的ExUnit测试中,我想测试调用创建路由的控制器,但是因为令牌总是随机的,所以我无法确定性地测试结果。

理想情况下,我希望能够在我的测试中存根 Ecto.UUID.generate ,因此它始终创建相同的UUID,以便我可以正确地测试响应。

谢谢 :)


I'm using Ecto.UUID.generate to create a random token on a user model.

In my ExUnit test, I want to test the controller that calls the creation route, however because the token is always random, I can't deterministically test the result.

Ideally, I want to be able to stub the Ecto.UUID.generate in my test so it always creates the same UUID so I can test the response correctly.

Thanks :)


原文:https://stackoverflow.com/questions/30093551
更新时间:2021-12-12 19:12

最满意答案

工作大部分时间和失败有时看起来像一个竞争条件。 Andrew Whitechapel撰写了与RequestComAddInAutomationService 1相关的竞争条件:

COMAddIns比赛条件

虽然他说竞争条件不应该是进程内VBA宏的问题,但问题可能发生在您的特定场景中。

尝试建议的解决方法并循环,直到您的Addin.Object有效(C#代码,类似于VBA):

while (utils == null)
{
    utils = (ComServiceOleMarshal.IAddinUtilities)addin.Object;
    System.Threading.Thread.Sleep(100);
}    
utils.DoSomething();

1关于你正在做的事情,他的博客上有很多有用的信息,所以千万不要错过相关的文章。


Turned out that Excel disabled the COM add-in. This is known to sometimes happen silently, without Excel complaining about anything.

So, since the add-in was registered with excel, the following line succeeded:

Set addin = Application.COMAddIns("My AddIn")

But since it was disabled, the object was not created and

Set automationObject = addin.Object

resulted in Nothing.

相关问答

更多
  • 只有Variant可以为Null ,而不是使用Nothing : Public Function parseEmployee(ByVal employeeId As Integer, _ ByVal ws As Worksheet) As employee Dim emp As New employee Dim empRow As Range If sheetContainsEmployee(employeeId, ...
  • 页面中有一个iframe。 这就是问题所在。 您必须首先获取iframe元素,然后获取与iframe关联的文档。 fileupload按钮位于iframe中。 IE.navigate "https://www.earthpoint.us/ExcelToKml.aspx" 'Show Window IE.Visible = True 'Wait for loaded WaitIE IE 'Select document Set IEDoc = IE.document Dim iBox As HTMLIFr ...
  • 原因之一 - 在MainFrame中调用getStudentsPass()时,尚未设置密码。 原因二 - 您在MainFrame中使用的SystemManagement对象和您在AddStudent中获得的SystemManagement对象完全不一样。 很难说没有更多的代码。 但我更喜欢Reason One - 检查程序流程,密码何时设置,什么时候尝试获取。 Reason one - password has not been set, when you call getStudentsPass() in ...
  • 单独填充10000个单元会让您觉得VSTO非常慢。 我可以用你提到的动态数组方法在很短的时间内完成它: static public void PopulateABigNumberOfCells(Excel.Application xlApp, DataTable dataTable) { //Turn off Excel updating SwitchApplicationSettings(xlApp,false); //Populate a 2D array - via a DataTable in t ...
  • Outlook API不是本机.NET框架。 为了与之交互,.NET依赖于编组和插入程序集,从而使其更容易出错和不稳定。 从我迄今为止看到的outlook API经验来看,我会坚持使用VBA,如果你遇到很多麻烦,你应该考虑检索暴露outlook扩展MAPI的第三方库。 Outlook API is not native .NET framework. To interact it with, .NET relies on marshaling and interrop assembly thus makin ...
  • 事实证明函数的Null值被传递给Date / Time变量。 我通过使用以下内容修复了这个问题: dim myDate as date dim myVar as variant myVar=getTableValue(idNum,"thisTable","idField", "valueField") if isNull(myVar) then myDate=0 else myDate=myVar endif 虽然它不检查myVar是否返回Date,但valueField的值是Date / Time ...
  • 您目前的问题似乎是OpenFile.lStructSize = LenB(strFile) 由于您将strFile设置为257,因此它包含574个字节。 基于结果,它看起来像lStructSize只会适用于文件,所以你必须使用你原来的OpenFile.lStructSize = LenB(OpenFile) 另外我不认为strptr的工作方式与你使用它的方式不同,它将字符串转换为指针,但反之亦然 如果这确实是问题之一,我写了一个将指针转换为字符串的函数。 不幸的是,它需要你传递长度,我试图从指针本身获取它时 ...
  • 所以@Dmitry提供的链接就是我所需要的。 通过使用运行对象表(ROT),我能够获得对Outlook加载的Outlook插件的引用。 因此,允许我调用其中的方法来删除邮件附件。 需要进行一些更改,包括: 将插件注册到ThisAddin_Startup()作为默认的OutlookAddin类使用静态构造函数,因此我无法在构造函数中引用Addin。 我还必须将我的代码移动到用户会话进程,因为这个帖子COMException(0x800401E3):具有计划任务的操作不可用(来自HRESULT的异常:0x800 ...
  • 工作大部分时间和失败有时看起来像一个竞争条件。 Andrew Whitechapel撰写了与RequestComAddInAutomationService 1相关的竞争条件: COMAddIns比赛条件 虽然他说竞争条件不应该是进程内VBA宏的问题,但问题可能发生在您的特定场景中。 尝试建议的解决方法并循环,直到您的Addin.Object有效(C#代码,类似于VBA): while (utils == null) { utils = (ComServiceOleMarshal.IAddinUti ...
  • 在这里找到了一个更好的解决方案http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/afd7f2ab-ee1e-495f-8071-9f2377a603fb private void FindUsedRange() { Excel.Worksheet wks = this.ActiveSheet as Excel.Worksheet; if (wks != null) { wks.UsedRange.Sel ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)