我有一个我想测试的课程.它看起来类似于:
public class ClassUnderTest
{
private Dependency1 dep1;
private Dependency1 getDependency1()
{
if (dep1 == null)
dep1 = new Dependency1();
return dep1;
}
public void methodUnderTest()
{
.... do something
getDependency1().InvokeSomething(..);
}
}
Run Code Online (Sandbox Code Playgroud)
类Dependency1很复杂,我想在编写单元测试时嘲笑它methodUnderTest().
我怎么做?
我正在尝试在 Linux 主机上运行的 docker 容器中设置 avahi。目的是让avahi公布一个自己的服务,让我找到docker主机的host和IP。
到目前为止,avahi 似乎在容器中运行良好,但我无法找到从主机外部搜索的服务。
我在谷歌上搜索了很多,并且有一些建议该怎么做,但它们似乎都是矛盾的和/或不安全的。
这是我到目前为止所得到的。
docker-compose.yml
version: "3.7"
services:
avahi:
container_name: avahi
build:
context: ./config/avahi
dockerfile: DockerFile
network: host
Run Code Online (Sandbox Code Playgroud)
Docker文件:
FROM alpine:3.13
RUN apk add --no-cache avahi avahi-tools
ADD avahi-daemon.conf /etc/avahi/avahi-daemon.conf
ADD psmb.service /etc/avahi/services/mpsu.service
ENTRYPOINT avahi-daemon --no-drop-root --no-rlimits
Run Code Online (Sandbox Code Playgroud)
avahi-daemon.conf:
[server]
enable-dbus=no
Run Code Online (Sandbox Code Playgroud)
psmb.service:(我的服务)
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">PSMB</name>
<service> <type>_mqtt._tcp</type> <port>1883</port>
<txt-record>info=MPS Service Host</txt-record>
</service>
</service-group>
Run Code Online (Sandbox Code Playgroud)
这是启动 avahi 时的终端:
> docker-compose up
Starting avahi ... done
Attaching to avahi
avahi | avahi-daemon 0.8 starting …Run Code Online (Sandbox Code Playgroud) 我有这个文件(example.json):
{
"messages" : [ "msg 1", "msg 2", "msg 3" ],
}
Run Code Online (Sandbox Code Playgroud)
然后我创建一个JsonNode这样的:
BufferedReader fileReader = new BufferedReader(new FileReader("example.json"));
JsonNode rootNode = mapper.readTree(fileReader);
Run Code Online (Sandbox Code Playgroud)
如何将数组元素值从“msg 1”更改为“msg 1A”而不删除元素并添加值为“msg 1A”的新元素?
我正在使用 vscode 调试我的 flutter 应用程序。
抛出未处理的异常并暂停执行。
调用堆栈只有三行深,并且只包含“颤动代码”,因此我无法看到异常的原因。
这是一种使调用堆栈更深的方法,以便我可以在代码中看到导致异常的女巫线吗?
出于某种原因(我真的不能记住为什么:))我决定只使用Java来配置Spring应用程序.另外我会尽量避免使用web.xml
我从接下来的两个java配置文件开始.ApplicationBootstrap.java
public class ApplicationBootstrap implements WebApplicationInitializer {
//public class Initializer
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationConfig.class);
rootContext.refresh();
// Manage the lifecycle of the root appcontext
servletContext.addListener(new ContextLoaderListener(rootContext));
servletContext.setInitParameter("defaultHtmlEscape", "true");
servletContext.setInitParameter("spring.profiles.active", "Production");
// now the config for the Dispatcher servlet
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
mvcContext.register(ApplicationConfig.class);
mvcContext.getEnvironment().setActiveProfiles("Production");
mvcContext.getEnvironment().setDefaultProfiles("Production");
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/api/*");
}
Run Code Online (Sandbox Code Playgroud)
和ApplicationConfig.java
@Configuration()
@Profile({"Production", "ControllerUnitTest"})
@EnableWebMvc
@ComponentScan( basePackages = "com.consius.activework.server" )
@EnableAspectJAutoProxy
public class ApplicationConfig extends WebMvcConfigurerAdapter …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于如何模拟RavenDb的问题.有一个共同的答案:"不要"
这让我陷入了一种奇怪的境地.模拟接口的最重要原因之一是测试我的代码如何对错误做出反应.
如果您无法模拟可能导致错误的对象,则注入错误会非常复杂.
我在这里想错了方向????
// LG
我正在使用 flutter_blue 作为使用蓝牙的 flutter 应用程序。
flutter_blue 向我展示了两个流: FlutterBlue.instance.connectedDevices FlutterBlue.instance.scanResults
我想将这两个流合并为一个并应用过滤器。
谷歌搜索我得到了 rxdart 的参考,但我仍然无法让它工作。请帮助 :)
是的,,,我知道有很多关于这个的话题,我想我已经阅读了其中的大部分,但要么我不理解答案,要么我无法将它们适应我的“案例”。
请注意,我的背景是电子设计,而不是软件设计,所以对于你们中的一些人来说,我的问题可能看起来很愚蠢,但是......我被困住了。
我设计了一块用于物联网用途的 PCB 板。它基于 ESP32 模块。我有 5 个按钮连接到 ESP。ESP32-IDF 对我来说太复杂了,所以我尝试使用 Arduino 框架。现在事情开始变得复杂了。
为了检测和消除按钮的抖动,我创建了一个名为 Button 的 C++ 类。下面可以看到一个骨架。
class Button {
..
..
private:
void memberCallback() {
...
}
public:
Button(const uint8_t gpio ) {
..
attachInterrup(digitalPinToInterrupt(gpio), memberCallback, FALLING);
..
}
..
}
Run Code Online (Sandbox Code Playgroud)
我还没有找到任何方法来定义“memberCallback”,而不会导致编译错误或根本无法工作。
这一定是一个常见问题,所以请建议我解决方案:)
编辑。看来我表达得不够清楚,抱歉。- 我知道如果我将memberCallback设置为静态,它至少会编译。问题是我计划使用 5 个这样的实例。静态回调意味着所有实例将运行相同的代码。5 个实例意味着 5 个不同的中断。我如何识别它们。
我有以下小代码示例:
std::function<bool()> isSet;
bool check() {
bool tmp;
return tmp;
}
std::function<bool()> isSet {
return check();
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误消息
could not convert 'isSet()' from 'bool' to 'std::function<bool()>'
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么以及如何解决它?