我一直在比较功能范式和面向对象范式。
作为其中的一部分 - 我想做一些性能测试。
我现在有一些看起来像这样的测试:
it("Some long running performance test", () => {
const result = myFunctionWithLotsOfData();
});
Run Code Online (Sandbox Code Playgroud)
现在,我只是打印此代码运行所需的时间(大约 5000 毫秒)。
我喜欢将 Jest 用于它提供的所有断言和模拟功能,并且它是实时重新加载等。
但是,我不希望这些测试一直进行,我会运行创建一个 npm 脚本,例如npm test:performance
,并且仅在存在环境变量或类似的情况下才运行这些测试。
做到这一点的最佳方法是什么?
好的,这就是我们得到的:
我们有两个库包,我们已经编译成罐子.
package starwars; public class JarJar { public void JarSayHello() { System.out.println("Jaaaaar!!"); } }
package barwars; public class BarBar { public void BarSayHello() { System.out.println("Baaaaa!!"); } }
我们编译这些
javac -d bin -sourcepath src src/barwars/BarBar.java jar cvf barwars.jar -C bin .
和
javac -d bin -sourcepath src src/starwars/JarJar.java jar cvf starwars.jar -C bin .
我们都很好地装进了罐子里.
现在我们想将这两个jar包含到另一个java项目中.
所以我们有
package a_pack; import starwars.JarJar; import barwars.BarBar; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); JarJar …
我有一个mkyong MVC教程的修改版本.
我添加了一个业务层类Counter
.
public class Counter {
private int i;
public int count()
{
return (this.i++);
}
//getters and setters and constructors
}
Run Code Online (Sandbox Code Playgroud)
在mvc-dispatcher-servlet.xml中:
<bean id="counter" class="com.mkyong.common.Counter" scope="session">
<property name="i" value="0"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
这很好用.
我现在想为这个类创建一个单元测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class TestCounter {
@Configuration
static class TestConfig
{
@Bean
public Counter c()
{
return new Counter();
}
}
@Autowired
private Counter c;
@Test
public void count_from1_returns2()
{
c.setI(1);
assertEquals(2, c.count());
}
}
Run Code Online (Sandbox Code Playgroud)
如果我像这样运行它,我会得到的
SEVERE: Caught exception while allowing …
Run Code Online (Sandbox Code Playgroud) 我有两节课:
public MyService
{
@Autowired
private MyDao myDao;
private List<Items> list;
@PostConstruct
private void init(){
list = myDao.getItems();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想要参与MyService
单元测试,所以我会嘲笑这个行为MyDao
.
XML:
<bean class = "com.package.MyService">
<bean class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.package.MyDao"/>
</bean>
<util:list id="responseItems" value-type="com.package.Item">
<ref bean="item1"/>
<ref bean="item2"/>
</util:list>
Run Code Online (Sandbox Code Playgroud)
单元测试:
@ContextConfiguration("/test-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class MyServiceTest{
@Autowired
MyService myService
@Autowired
MyDao myDao;
@Resource
@Qualifier("responseItems")
private List<Item> responseItems;
@Before
public void setupTests() {
reset(myDao);
when(myDao.getItems()).thenReturn(responseItems);
}
}
Run Code Online (Sandbox Code Playgroud)
这个问题是MyService
bean被创建,并且在定义模拟行为之前调用了它的@PostConstruct bean.
如何在XML中定义模拟行为,或者@PostConstruct
在单元测试设置之后延迟?
我正在创建一个与第三方应用程序集成的应用程序。
为此,登录用户提交用于第三方集成的 API 密钥。
如果他们提交的 API 密钥无效 - (并从第三方返回 401),我应该返回哪个 HTTP 响应?
从我的应用程序返回 401 听起来令人困惑,因为从前端的角度来看,不清楚它们是否未经我的应用程序或第三方应用程序验证。
我很想给它一个 400 - 就好像他们提交了一个带有无效电子邮件地址的表单等。
我有一个问题,有一些进口
import foo from ".";
import bar from "..";
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,在我的机器上这会给我错误;
error `..` import should occur before import of `.` import/order
Run Code Online (Sandbox Code Playgroud)
然而,在我朋友的机器上,这看起来很好,交换它们会给出相同的错误,但相反。
如果我们运行./node_modules/.bin/eslint -v
两者都显示为 4.19.1。
这里可能发生了什么导致 eslint 表现不同的情况?空格或行结尾周围有什么东西吗?
我使用的是compass watch
与Chrome的资源映射到修改我.scss在Chrome浏览器,它的工作好.
但是,我保存.scss文件的所有时间,罗盘会在重新编译.css之前检查其配置中的每个精灵,大约需要三秒钟.
我可以使用设置来跳过图像以获得更多即时反馈吗?
我正在尝试制作一排按钮,其中的按钮将具有相同的大小,但应尽可能小-因此每个按钮都与最大的按钮具有相同的大小。
我怎样才能做到这一点?
div {
border: solid 1px black;
margin: 5px;
padding: 5px;
background-color: #fff;
}
.container {
display: flex;
flex-flow: row nowrap;
justify-content: flex-end;
}
.item {
background-color: #eef;
flex: 0 1 auto;
white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="item">this one is quite long</div>
<div class="item">short</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这里的这个问题基本上问了同样的问题:
但没有得到正确的答案。
如果我们查看官方文档示例,他们可以选择选择地址类型。但是,在它上面,我们可以看到它允许我们只选择街道:
有没有办法让 Places Autocomplete 只选择真实地址?
我有一个应用程序,用户将单击应用程序的各个部分,这将在右侧的抽屉中显示某种配置选项。
我对此的解决方案是将要显示的任何内容存储在上下文中。这样,抽屉只需要从上下文中检索其内容,并且需要设置内容的任何部分都可以直接通过上下文进行设置。
这是一个CodeSandbox 演示了这一点。
关键代码片段:
const MainContent = () => {
const items = ["foo", "bar", "biz"];
const { setContent } = useContext(DrawerContentContext);
/**
* Note that in the real world, these components could exist at any level of nesting
*/
return (
<Fragment>
{items.map((v, i) => (
<Button
key={i}
onClick={() => {
setContent(<div>{v}</div>);
}}
>
{v}
</Button>
))}
</Fragment>
);
};
const MyDrawer = () => {
const classes = useStyles();
const { content } = useContext(DrawerContentContext); …
Run Code Online (Sandbox Code Playgroud)