-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutant still survive although test failed #4582
Comments
Hi @AkiraNoob , thanks for opening this issue. I'll have a look at your source code and try to figure out what is happening. |
So far there is one thing that has caught my attention, when i run Stryker with the change that should let a test fail. The initial test run fails. This means that the problem is not with finding the test. Besides that i don't know what's going wrong here. @nicojs do you have a clue? |
I think i've found the issue. Your tests seem to share state. This change: --- a/server/src/api/service/auth.service.ts
+++ b/server/src/api/service/auth.service.ts
@@ -68,7 +68,7 @@ const authService = {
fullName: verifiedRefreshToken.fullName,
};
- await RefreshTokenModel.deleteMany({ userId: new mongoose.Types.ObjectId(userData.id) });
+ await RefreshTokenModel.deleteMany({}); Makes your tests fail when you run them all serially (the test --- a/server/__test__/api/service/auth.service.test.ts
+++ b/server/__test__/api/service/auth.service.test.ts
@@ -55,7 +55,7 @@ describe('Testing auth service', () => {
const spyedRefreshDelete = jest.spyOn(RefreshTokenModel, 'deleteMany');
const spyedFindUser = jest.spyOn(UserModel, 'findOne');
const spyedBcryptCompare = jest.spyOn(bcryptCommon, 'bcryptCompareSync');
- it('should return statusCode 200 and data should contain {token, refreshToken} and message is "Login successfully"', async () => {
+ it.only('should return statusCode 200 and data should contain {token, refreshToken} and message is "Login successfully"', async () => { Focussing tests is what StrykerJS does when you set coverageAnalysis to I would suggest making your unit test independent of each other. You can do this by removing the global state, and instead initialing variables inside For example: --- a/server/__test__/api/service/auth.service.test.ts
+++ b/server/__test__/api/service/auth.service.test.ts
@@ -11,20 +11,26 @@ import UserModel from '../../../src/model/user';
import { TLocalLoginPayload, TRegisterPayload } from '../../../src/types/api/auth.types';
import { TUserSchema } from '../../../src/types/schema/user.schema.types';
-const userPayload: TUserSchema = {
- email: '[email protected]',
- password: bcryptCommon.bcryptHashSync('Tester@001'),
- fullName: 'Tester 001',
- avatar: 's3_img_string',
- dateOfBirth: new Date(),
-};
-
-const mockRegisterPayload: TRegisterPayload = {
- ...omit(userPayload, ['avatar', 'dateOfBirth']),
- password: 'Tester@001',
-};
-
-const mockLocalLoginPayload: TLocalLoginPayload = omit(mockRegisterPayload, 'fullName');
+let userPayload: TUserSchema;
+let mockRegisterPayload: TRegisterPayload;
+let mockLocalLoginPayload: TLocalLoginPayload;
+
+beforeEach(() => {
+ userPayload = {
+ email: '[email protected]',
+ password: bcryptCommon.bcryptHashSync('Tester@001'),
+ fullName: 'Tester 001',
+ avatar: 's3_img_string',
+ dateOfBirth: new Date(),
+ };
+
+ mockRegisterPayload = {
+ ...omit(userPayload, ['avatar', 'dateOfBirth']),
+ password: 'Tester@001',
+ };
+
+ mockLocalLoginPayload = omit(mockRegisterPayload, 'fullName');
+}); |
thanks @nicojs and @odinvanderlinden for help me out, i really appriciate it! Seem like that is the reason |
sorry for re-open this issue but somehow i think it not solves my case, i provide a brief version of my code:
|
i belive that if it runs to return statement, it means that API is resolves successfully and MUST return message in image |
Sorry for my mistake, i try research more and try some approaches: #2989 #3068 and trouble shooting but my issue still occurs. I have created a smaller repository to focus on a single unit here. You can see that if i run npm run mutation-test 1 mutant still survive but the test is failed (i try to isolate the testcase as suggest). Hope this repository will help to solve my issue |
Sorry for my hurry but any update on this? |
Hi @AkiraNoob sorry for the late response, I haven't had a lot of time to work on Stryker lately. I have taken a look at your new repository. And it seems that you still make use of shared state. For every single test you should clear your in memory database. This is not the case right now. For instance the after all method where you clear the user should be a AfterEacht method to make sure you start every test with a clean sheet. I hope this helps! |
Question
Hello everyone, this is my first question so if i make any mistake, pls let me know. Peace
Back to the question, can s.o explain for me why this mutant keep survived although when i try that mutant to the code itself, the test is failed.
My repo: https://github.com/AkiraNoob/kiem_chung
Test case:
service:
mutant
Stryker environment
Additional context
my stryker config:
my jest config
Also node that i currently use node 18.18.2
The text was updated successfully, but these errors were encountered: